How to use toContainEntry method in jest-extended

Best JavaScript code snippet using jest-extended

request-supplies.test.js

Source:request-supplies.test.js Github

copy

Full Screen

...44 const res = await api.get('/request-supplies', token);45 expect(res.status).toBe(OK);46 expect(res.body.requestSupplies).toBeArrayOfSize(1);47 const [reqSupply] = res.body.requestSupplies;48 expect(reqSupply).toContainEntry(['id', 1]);49 expect(reqSupply).toContainEntry(['userId', loggedUser.id]);50 expect(reqSupply).toContainEntry(['supplyId', 1]);51 expect(reqSupply).toContainEntry(['areaId', 1]);52 expect(reqSupply).toContainEntry(['amount', 10]);53 expect(reqSupply).toContainEntry(['status', 'Pending']);54 });55 test('Only pending', async () => {56 await RequestSupply.create(57 {58 userId: loggedUser.id,59 supply: { name: 'Gloves', stock: 1000 },60 area: { name: 'The Citadel' },61 amount: 30,62 status: 'Approved',63 },64 {65 include: [66 { model: Supply, as: 'supply' },67 { model: Area, as: 'area' },68 ],69 },70 );71 await RequestSupply.create({72 userId: loggedUser.id,73 supplyId: 1,74 areaId: 1,75 amount: 20,76 status: 'Pending',77 });78 let res = await api.get('/request-supplies', token);79 expect(res.status).toBe(OK);80 expect(res.body.requestSupplies).toBeArrayOfSize(2);81 res = await api.get('/request-supplies?status=Pending', token);82 expect(res.status).toBe(OK);83 expect(res.body.requestSupplies).toBeArrayOfSize(1);84 const [reqSupply] = res.body.requestSupplies;85 expect(reqSupply).toContainEntry(['id', 2]);86 expect(reqSupply).toContainEntry(['userId', loggedUser.id]);87 expect(reqSupply).toContainEntry(['supplyId', 1]);88 expect(reqSupply).toContainEntry(['areaId', 1]);89 expect(reqSupply).toContainEntry(['amount', 20]);90 expect(reqSupply).toContainEntry(['status', 'Pending']);91 });92 });93 describe('With Admin Token', () => {94 test('Empty list', async () => {95 const res = await api.get('/request-supplies', tokenAdmin);96 expect(res.status).toBe(OK);97 expect(res.body.requestSupplies).toBeArrayOfSize(0);98 });99 test('With data', async () => {100 await RequestSupply.create(101 {102 userId: loggedUser.id,103 supply: { name: 'Gloves', stock: 1000 },104 area: { name: 'The Citadel' },105 amount: 10,106 status: 'Pending',107 },108 {109 include: [110 { model: Supply, as: 'supply' },111 { model: Area, as: 'area' },112 ],113 },114 );115 const res = await api.get('/request-supplies', tokenAdmin);116 expect(res.status).toBe(OK);117 expect(res.body.requestSupplies).toBeArrayOfSize(1);118 const [reqSupply] = res.body.requestSupplies;119 expect(reqSupply).toContainEntry(['id', 1]);120 expect(reqSupply).toContainEntry(['userId', loggedUser.id]);121 expect(reqSupply).toContainEntry(['supplyId', 1]);122 expect(reqSupply).toContainEntry(['areaId', 1]);123 expect(reqSupply).toContainEntry(['amount', 10]);124 expect(reqSupply).toContainEntry(['status', 'Pending']);125 });126 test('Only pending', async () => {127 await RequestSupply.create(128 {129 userId: loggedUser.id,130 supply: { name: 'Gloves', stock: 1000 },131 area: { name: 'The Citadel' },132 amount: 30,133 status: 'Approved',134 },135 {136 include: [137 { model: Supply, as: 'supply' },138 { model: Area, as: 'area' },139 ],140 },141 );142 await RequestSupply.create({143 userId: loggedUser.id,144 supplyId: 1,145 areaId: 1,146 amount: 20,147 status: 'Pending',148 });149 let res = await api.get('/request-supplies', tokenAdmin);150 expect(res.status).toBe(OK);151 expect(res.body.requestSupplies).toBeArrayOfSize(2);152 res = await api.get('/request-supplies?status=Pending', tokenAdmin);153 expect(res.status).toBe(OK);154 expect(res.body.requestSupplies).toBeArrayOfSize(1);155 const [reqSupply] = res.body.requestSupplies;156 expect(reqSupply).toContainEntry(['id', 2]);157 expect(reqSupply).toContainEntry(['userId', loggedUser.id]);158 expect(reqSupply).toContainEntry(['supplyId', 1]);159 expect(reqSupply).toContainEntry(['areaId', 1]);160 expect(reqSupply).toContainEntry(['amount', 20]);161 expect(reqSupply).toContainEntry(['status', 'Pending']);162 });163 });164 });165 describe('GET /request-supplies/:id', () => {166 test('Without Token response error', async () => {167 const res = await api.get('/request-supplies');168 expect(res).not.toBeValidToken();169 });170 describe('With User Token', () => {171 test('With data', async () => {172 const rs = await RequestSupply.create(173 {174 userId: loggedUser.id,175 supply: { name: 'Gloves', stock: 1000 },176 area: { name: 'The Citadel' },177 amount: 10,178 status: 'Pending',179 },180 {181 include: [182 { model: Supply, as: 'supply' },183 { model: Area, as: 'area' },184 ],185 },186 );187 const res = await api.get(`/request-supplies/${rs.id}`, token);188 expect(res.status).toBe(OK);189 expect(res.body).toBeObject();190 expect(res.body).toContainEntry(['id', 1]);191 expect(res.body).toContainEntry(['userId', loggedUser.id]);192 expect(res.body).toContainEntry(['supplyId', 1]);193 expect(res.body).toContainEntry(['areaId', 1]);194 expect(res.body).toContainEntry(['amount', 10]);195 expect(res.body).toContainEntry(['status', 'Pending']);196 });197 test('Error when invalid id', async () => {198 const anotherUser = await builder.register({ email: 'juan@nieve.com' });199 const rs = await RequestSupply.create(200 {201 userId: anotherUser.id,202 supply: { name: 'Gloves', stock: 1000 },203 area: { name: 'The Citadel' },204 amount: 30,205 status: 'Approved',206 },207 {208 include: [209 { model: Supply, as: 'supply' },210 { model: Area, as: 'area' },211 ],212 },213 );214 const res = await api.get(`/request-supplies/${rs.id}`, token);215 expect(res.status).toBe(BAD_REQUEST);216 expect(res.body).toContainEntry(['status', BAD_REQUEST]);217 expect(res.body).toContainEntry([218 'message',219 'Request Supply not exists',220 ]);221 });222 });223 describe('With Admin Token', () => {224 test('With data', async () => {225 const rs = await RequestSupply.create(226 {227 userId: loggedUser.id,228 supply: { name: 'Gloves', stock: 1000 },229 area: { name: 'The Citadel' },230 amount: 10,231 status: 'Pending',232 },233 {234 include: [235 { model: Supply, as: 'supply' },236 { model: Area, as: 'area' },237 ],238 },239 );240 const res = await api.get(`/request-supplies/${rs.id}`, tokenAdmin);241 expect(res.status).toBe(OK);242 expect(res.body).toBeObject();243 expect(res.body).toContainEntry(['id', 1]);244 expect(res.body).toContainEntry(['userId', loggedUser.id]);245 expect(res.body).toContainEntry(['supplyId', 1]);246 expect(res.body).toContainEntry(['areaId', 1]);247 expect(res.body).toContainEntry(['amount', 10]);248 expect(res.body).toContainEntry(['status', 'Pending']);249 });250 test('Error when invalid id', async () => {251 const rs = await RequestSupply.create(252 {253 userId: loggedUser.id,254 supply: { name: 'Gloves', stock: 1000 },255 area: { name: 'The Citadel' },256 amount: 30,257 status: 'Approved',258 },259 {260 include: [261 { model: Supply, as: 'supply' },262 { model: Area, as: 'area' },263 ],264 },265 );266 const res = await api.get(`/request-supplies/${rs.id + 1}`, tokenAdmin);267 expect(res.status).toBe(BAD_REQUEST);268 expect(res.body).toContainEntry(['status', BAD_REQUEST]);269 expect(res.body).toContainEntry([270 'message',271 'Request Supply not exists',272 ]);273 });274 });275 });276 describe('DELETE /request-supplies/:id', () => {277 test('Without Token response error', async () => {278 const res = await api.get('/request-supplies');279 expect(res).not.toBeValidToken();280 });281 describe('With Token', () => {282 test('With data', async () => {283 const rs = await RequestSupply.create(284 {285 userId: loggedUser.id,286 supply: { name: 'Gloves', stock: 1000 },287 area: { name: 'The Citadel' },288 amount: 10,289 status: 'Pending',290 },291 {292 include: [293 { model: Supply, as: 'supply' },294 { model: Area, as: 'area' },295 ],296 },297 );298 let res = await api.get(`/request-supplies/${rs.id}`, token);299 expect(res.status).toBe(OK);300 expect(res.body).toContainEntry(['status', 'Pending']);301 res = await api.delete(`/request-supplies/${rs.id}`, token);302 expect(res.status).toBe(OK);303 expect(res.body).toBeObject();304 expect(res.body).toContainEntry(['status', 'Canceled']);305 expect(res.body).toContainEntry(['id', 1]);306 expect(res.body).toContainEntry(['userId', loggedUser.id]);307 expect(res.body).toContainEntry(['supplyId', 1]);308 expect(res.body).toContainEntry(['areaId', 1]);309 expect(res.body).toContainEntry(['amount', 10]);310 });311 test('Error when invalid id', async () => {312 const anotherUser = await builder.register({ email: 'juan@nieve.com' });313 const rs = await RequestSupply.create(314 {315 userId: anotherUser.id,316 supply: { name: 'Gloves', stock: 1000 },317 area: { name: 'The Citadel' },318 amount: 30,319 status: 'Approved',320 },321 {322 include: [323 { model: Supply, as: 'supply' },324 { model: Area, as: 'area' },325 ],326 },327 );328 const res = await api.delete(`/request-supplies/${rs.id}`, token);329 expect(res.status).toBe(BAD_REQUEST);330 expect(res.body).toContainEntry(['status', BAD_REQUEST]);331 expect(res.body).toContainEntry([332 'message',333 'Request Supply not exists',334 ]);335 });336 });337 });338 describe('PATCH /request-supplies/:id { "status": "Approved" }', () => {339 test('Without Token response error', async () => {340 const res = await api.patch(341 '/request-supplies/1',342 { status: 'Approved' },343 token,344 );345 expect(res).not.toBeValidToken();346 });347 describe('With Admin Token', () => {348 test('Approve when is Pending', async () => {349 const rs = await RequestSupply.create(350 {351 userId: loggedUser.id,352 supply: { name: 'Gloves', stock: 1000 },353 area: { name: 'The Citadel' },354 amount: 10,355 status: 'Pending',356 },357 {358 include: [359 { model: Supply, as: 'supply' },360 { model: Area, as: 'area' },361 ],362 },363 );364 let res = await api.get(`/request-supplies/${rs.id}`, tokenAdmin);365 expect(res.status).toBe(OK);366 expect(res.body).toContainEntry(['status', 'Pending']);367 res = await api.patch(368 `/request-supplies/${rs.id}`,369 { status: 'Approved' },370 tokenAdmin,371 );372 expect(res.status).toBe(OK);373 expect(res.body).toBeObject();374 expect(res.body).toContainEntry(['status', 'Approved']);375 expect(res.body).toContainEntry(['id', 1]);376 expect(res.body).toContainEntry(['userId', loggedUser.id]);377 expect(res.body).toContainEntry(['supplyId', 1]);378 expect(res.body).toContainEntry(['areaId', 1]);379 expect(res.body).toContainEntry(['amount', 10]);380 });381 test('Reject when is Pending', async () => {382 const rs = await RequestSupply.create(383 {384 userId: loggedUser.id,385 supply: { name: 'Gloves', stock: 1000 },386 area: { name: 'The Citadel' },387 amount: 10,388 status: 'Pending',389 },390 {391 include: [392 { model: Supply, as: 'supply' },393 { model: Area, as: 'area' },394 ],395 },396 );397 let res = await api.get(`/request-supplies/${rs.id}`, tokenAdmin);398 expect(res.status).toBe(OK);399 expect(res.body).toContainEntry(['status', 'Pending']);400 res = await api.patch(401 `/request-supplies/${rs.id}`,402 { status: 'Rejected' },403 tokenAdmin,404 );405 expect(res.status).toBe(OK);406 expect(res.body).toBeObject();407 expect(res.body).toContainEntry(['status', 'Rejected']);408 expect(res.body).toContainEntry(['id', 1]);409 expect(res.body).toContainEntry(['userId', loggedUser.id]);410 expect(res.body).toContainEntry(['supplyId', 1]);411 expect(res.body).toContainEntry(['areaId', 1]);412 expect(res.body).toContainEntry(['amount', 10]);413 });414 test('Error when id not Pending', async () => {415 const rs = await RequestSupply.create(416 {417 userId: loggedUser.id,418 supply: { name: 'Gloves', stock: 1000 },419 area: { name: 'The Citadel' },420 amount: 30,421 status: 'Canceled',422 },423 {424 include: [425 { model: Supply, as: 'supply' },426 { model: Area, as: 'area' },427 ],428 },429 );430 const res = await api.patch(431 `/request-supplies/${rs.id}`,432 { status: 'Approved' },433 tokenAdmin,434 );435 expect(res.status).toBe(BAD_REQUEST);436 expect(res.body).toContainEntry(['status', BAD_REQUEST]);437 expect(res.body).toContainEntry([438 'message',439 'Request Supply is not Pending',440 ]);441 });442 test('Error when status sent is invalid', async () => {443 const rs = await RequestSupply.create(444 {445 userId: loggedUser.id,446 supply: { name: 'Gloves', stock: 1000 },447 area: { name: 'The Citadel' },448 amount: 30,449 status: 'Pending',450 },451 {452 include: [453 { model: Supply, as: 'supply' },454 { model: Area, as: 'area' },455 ],456 },457 );458 const res = await api.patch(459 `/request-supplies/${rs.id}`,460 { status: 'Canceled' },461 tokenAdmin,462 );463 expect(res.status).toBe(BAD_REQUEST);464 expect(res.body).toContainEntry(['status', BAD_REQUEST]);465 expect(res.body).toContainEntry([466 'message',467 'Invalid Request Supply Status',468 ]);469 });470 test('Error when invalid id', async () => {471 const rs = await RequestSupply.create(472 {473 userId: loggedUser.id,474 supply: { name: 'Gloves', stock: 1000 },475 area: { name: 'The Citadel' },476 amount: 30,477 status: 'Pending',478 },479 {480 include: [481 { model: Supply, as: 'supply' },482 { model: Area, as: 'area' },483 ],484 },485 );486 const res = await api.patch(487 `/request-supplies/${rs.id + 1}`,488 { status: 'Approved' },489 tokenAdmin,490 );491 expect(res.status).toBe(BAD_REQUEST);492 expect(res.body).toContainEntry(['status', BAD_REQUEST]);493 expect(res.body).toContainEntry([494 'message',495 'Request Supply not exists',496 ]);497 });498 });499 });500 describe('POST /request-supplies', () => {501 test('Without Token response error', async () => {502 const data = {};503 const res = await api.post('/request-supplies', data);504 expect(res).not.toBeValidToken();505 });506 describe('With Token', () => {507 test('Data Validation (empty data)', async () => {508 const data = {};509 const res = await api.post('/request-supplies', data, token);510 expect(res.status).toBe(BAD_REQUEST);511 expect(res.body).toContainEntry(['status', BAD_REQUEST]);512 expect(res.body).toContainEntry(['message', 'Validation Errors']);513 expect(res.body.errors).toIncludeAllMembers([514 'Invalid Area ID',515 'Invalid Supply ID',516 ]);517 });518 test('Data Validation (invalid data)', async () => {519 const area = await Area.create({ name: 'Therapy' });520 const supply = await Supply.create({ name: 'Gloves' });521 const data = {522 areaId: area.id + 1,523 supplyId: supply.id + 1,524 };525 const res = await api.post('/request-supplies', data, token);526 expect(res.status).toBe(BAD_REQUEST);527 expect(res.body).toContainEntry(['status', BAD_REQUEST]);528 expect(res.body).toContainEntry(['message', 'Validation Errors']);529 expect(res.body.errors).toIncludeAllMembers([530 'Invalid Area ID',531 'Invalid Supply ID',532 ]);533 });534 test('Success Request Supplies', async () => {535 const area = await Area.create({ name: 'Therapy' });536 const supply = await Supply.create({ name: 'Gloves' });537 const data = {538 areaId: area.id,539 supplyId: supply.id,540 amount: 3,541 };542 const res = await api.post('/request-supplies', data, token);543 expect(res.status).toBe(CREATED);544 expect(res.body).toContainEntry(['created', true]);545 expect(res.body.request).toContainKey('userId');546 expect(res.body.request).toContainEntry(['id', 1]);547 expect(res.body.request).toContainEntry(['areaId', area.id]);548 expect(res.body.request).toContainEntry(['supplyId', supply.id]);549 expect(res.body.request).toContainEntry(['amount', 3]);550 expect(res.body.request).toContainEntry(['status', 'Pending']);551 });552 });553 });...

Full Screen

Full Screen

s3wrapper.spec.ts

Source:s3wrapper.spec.ts Github

copy

Full Screen

...86 const file = SAMPLE_FILE1;87 const folder = 'test-folder';88 const destination = path.join(folder, path.basename(file));89 void s3Wrapper.uploadFile(SAMPLE_FILE1, folder).then((response) => {90 expect(response).toBeDefined().toContainEntry(['Key', destination]);91 done();92 });93 });94 it('upload twice a file (without replace)', async (done) => {95 expect.assertions(1);96 await s3Wrapper.uploadFile(SAMPLE_FILE1);97 s3Wrapper.uploadFile(SAMPLE_FILE1).catch((err) => {98 expect(err).toBeDefined();99 done();100 });101 });102 it('upload twice a file (with replace)', async (done) => {103 expect.assertions(1);104 await s3Wrapper.uploadFile(SAMPLE_FILE1);105 void s3Wrapper.uploadFile(SAMPLE_FILE1, undefined, { replace: true }).then((response) => {106 expect(response).toBeDefined();107 done();108 });109 });110 it('upload a file with expireDate', (done) => {111 expect.assertions(1);112 const today = new Date();113 const expireDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1);114 void s3Wrapper.uploadFile(SAMPLE_FILE1, undefined, { expireDate }).then((response) => {115 expect(response).toBeDefined();116 done();117 });118 });119 it('upload a file with expire', (done) => {120 expect.assertions(1);121 void s3Wrapper.uploadFile(SAMPLE_FILE1, undefined, { expire: '1d' }).then((response) => {122 expect(response).toBeDefined();123 done();124 });125 });126 describe('create new bucket', () => {127 const alternativeBucket = `not-exiting-bucket-${getRandomBucketName()}`;128 beforeEach(() => {129 s3Wrapper.setConfig({ endpoint: Config.ENDPOINT, bucket: alternativeBucket });130 });131 afterEach(() => {132 void clearBucket(alternativeBucket);133 });134 it('upload to a not created bucket (without create)', (done) => {135 expect.assertions(1);136 s3Wrapper.uploadFile(SAMPLE_FILE1, undefined, { create: false }).catch((error) => {137 expect(error).toBeDefined();138 done();139 });140 });141 it('upload to a not created bucket (with create)', (done) => {142 expect.assertions(1);143 void s3Wrapper.uploadFile(SAMPLE_FILE1, undefined, { create: true }).then((response) => {144 expect(response).toBeDefined();145 done();146 });147 });148 });149 });150 describe('upload multiple files', () => {151 it('upload 2 files without compress', (done) => {152 expect.assertions(9);153 void s3Wrapper.uploadFiles([SAMPLE_FILE1, SAMPLE_FILE2], undefined, { compress: false }).then((response) => {154 const file1 = path.basename(SAMPLE_FILE1);155 const file2 = path.basename(SAMPLE_FILE2);156 expect(response).toBeDefined().toBeObject().toContainAllKeys([SAMPLE_FILE1, SAMPLE_FILE2]);157 expect(response[SAMPLE_FILE1]).toBeDefined().toBeObject().toContainEntry(['Key', file1]);158 expect(response[SAMPLE_FILE2]).toBeDefined().toBeObject().toContainEntry(['Key', file2]);159 done();160 });161 });162 it('upload 2 files with compress', (done) => {163 expect.assertions(3);164 void s3Wrapper.uploadFiles([SAMPLE_FILE1, SAMPLE_FILE2], undefined, { compress: true }).then((response) => {165 expect(response).toBeDefined().toBeObject();166 expect(Object.keys(response)).toHaveLength(1);167 done();168 });169 });170 it('upload a directory without compress', (done) => {171 expect.assertions(21);172 const dir = path.dirname(SAMPLE_FILE1);173 void s3Wrapper.uploadFiles(dir, undefined, { compress: false }).then((response) => {174 const file1 = path.basename(SAMPLE_FILE1);175 const file2 = path.basename(SAMPLE_FILE2);176 expect(response).toBeDefined().toBeObject().toContainAllKeys([SAMPLE_FILE1, SAMPLE_FILE2, SAMPLE_FILE3]);177 expect(response[SAMPLE_FILE1]).toBeDefined().toBeObject().toContainEntry(['Key', file1]);178 expect(response[SAMPLE_FILE2]).toBeDefined().toBeObject().toContainEntry(['Key', file2]);179 expect(response[SAMPLE_FILE3])180 .toBeDefined()181 .toBeObject()182 .toContainEntry(['Key', SAMPLE_FILE3.replace(dir + '/', '')]);183 const location1 = response[SAMPLE_FILE1].Location;184 const path1 = new URL(location1).pathname;185 const calcPath1 = path.join('/', bucketName, path.relative(dir, SAMPLE_FILE1));186 expect(path1).toBeDefined().toBeString().toBe(calcPath1);187 const location2 = response[SAMPLE_FILE2].Location;188 const path2 = new URL(location2).pathname;189 const calcPath2 = path.join('/', bucketName, path.relative(dir, SAMPLE_FILE2));190 expect(path2).toBeDefined().toBeString().toBe(calcPath2);191 const location3 = response[SAMPLE_FILE3].Location;192 const path3 = new URL(location3).pathname;193 const calcPath3 = path.join('/', bucketName, path.relative(dir, SAMPLE_FILE3));194 expect(path3).toBeDefined().toBeString().toBe(calcPath3);195 done();196 });197 });198 it('upload a directory with compress', (done) => {199 expect.assertions(3);200 const dir = path.dirname(SAMPLE_FILE1);201 void s3Wrapper.uploadFiles(dir, undefined, { compress: true }).then((response) => {202 expect(response).toBeDefined().toBeObject();203 expect(Object.keys(response)).toHaveLength(1);204 done();205 });206 });207 it('upload a directory wildcard without compress', (done) => {208 expect.assertions(21);209 const dir = path.dirname(SAMPLE_FILE1);210 void s3Wrapper.uploadFiles(path.join(dir, '*'), undefined, { compress: false }).then((response) => {211 const file1 = path.basename(SAMPLE_FILE1);212 const file2 = path.basename(SAMPLE_FILE2);213 expect(response).toBeDefined().toBeObject().toContainAllKeys([SAMPLE_FILE1, SAMPLE_FILE2, SAMPLE_FILE3]);214 expect(response[SAMPLE_FILE1]).toBeDefined().toBeObject().toContainEntry(['Key', file1]);215 expect(response[SAMPLE_FILE2]).toBeDefined().toBeObject().toContainEntry(['Key', file2]);216 expect(response[SAMPLE_FILE3])217 .toBeDefined()218 .toBeObject()219 .toContainEntry(['Key', SAMPLE_FILE3.replace(dir + '/', '')]);220 const location1 = response[SAMPLE_FILE1].Location;221 const path1 = new URL(location1).pathname;222 const calcPath1 = path.join('/', bucketName, path.relative(dir, SAMPLE_FILE1));223 expect(path1).toBeDefined().toBeString().toBe(calcPath1);224 const location2 = response[SAMPLE_FILE2].Location;225 const path2 = new URL(location2).pathname;226 const calcPath2 = path.join('/', bucketName, path.relative(dir, SAMPLE_FILE2));227 expect(path2).toBeDefined().toBeString().toBe(calcPath2);228 const location3 = response[SAMPLE_FILE3].Location;229 const path3 = new URL(location3).pathname;230 const calcPath3 = path.join('/', bucketName, path.relative(dir, SAMPLE_FILE3));231 expect(path3).toBeDefined().toBeString().toBe(calcPath3);232 done();233 });234 });235 it('upload a directory wildcard with compress', (done) => {236 expect.assertions(3);237 const dir = path.dirname(SAMPLE_FILE1);238 void s3Wrapper.uploadFiles(path.join(dir, '*'), undefined, { compress: true }).then((response) => {239 expect(response).toBeDefined().toBeObject();240 expect(Object.keys(response)).toHaveLength(1);241 done();242 });243 });244 });245 describe('Delete older files', () => {246 it('delete all files older than 5secs', async () => {247 await s3Wrapper.uploadFile(SAMPLE_FILE1);248 await s3Wrapper.uploadFile(SAMPLE_FILE2, 'sample-folder');249 await wait(8);250 await s3Wrapper.uploadFile(SAMPLE_FILE2);251 const deleted = await s3Wrapper.cleanOlder('5s');252 expect(deleted).toBeDefined().toBeObject().toContainAllKeys(['Deleted', 'Errors']);253 expect(deleted.Errors).toBeEmpty();254 expect(deleted.Deleted).toBeDefined().toBeArray().toHaveLength(2);255 const list = await s3Wrapper.getFiles();256 expect(list).toBeDefined().toBeArray().toHaveLength(1);257 expect(list[0])258 .toBeDefined()259 .toBeObject()260 .toContainEntry(['Key', path.basename(SAMPLE_FILE2)]);261 });262 it('delete files older than 5secs in folder', async () => {263 await s3Wrapper.uploadFile(SAMPLE_FILE1);264 const folderName = 'sample-folder';265 await s3Wrapper.uploadFile(SAMPLE_FILE2, folderName);266 await wait(8);267 await s3Wrapper.uploadFile(SAMPLE_FILE2);268 const deleted = await s3Wrapper.cleanOlder('5s', folderName);269 expect(deleted).toBeDefined().toBeObject().toContainAllKeys(['Deleted', 'Errors']);270 expect(deleted.Errors).toBeEmpty();271 expect(deleted.Deleted).toBeDefined().toBeArray().toHaveLength(1);272 const list = await s3Wrapper.getFiles();273 expect(list).toBeDefined().toBeArray().toHaveLength(2);274 });...

Full Screen

Full Screen

posts.test.js

Source:posts.test.js Github

copy

Full Screen

...31 imageLocation,32 };33 const res = await api.post('/posts', data, token);34 expect(res.status).toBe(CREATED);35 expect(res.body).toContainEntry(['status', CREATED]);36 expect(res.body.resource).toContainEntry(['id', 1]);37 expect(res.body.resource).toContainEntry(['description', description]);38 expect(res.body.resource).toContainEntry([39 'imageLocation',40 imageLocation,41 ]);42 });43 test('should response error when post with empty data', async () => {44 const data = {};45 const res = await api.post('/posts', data, token);46 expect(res.status).toBe(BAD_REQUEST);47 expect(res.body).toContainEntry(['status', BAD_REQUEST]);48 expect(res.body).toContainEntry(['message', 'Validation Errors']);49 expect(res.body.errors).toIncludeAllMembers([50 'Description is required',51 'Image location is required',52 ]);53 });54 });55});56describe('GET /posts', () => {57 let token;58 beforeEach(async () => {59 await clearDatabase();60 token = await builder.generateToken({ email: 'peggy.olson@mail.com' });61 });62 const createPosts = async (number) => {63 const results = [];64 for (let i = 0; i < number; i += 1) {65 const data = {66 description: 'Some post description',67 imageLocation: 'www.myLocation.com/image1234',68 };69 results.push(api.post('/posts', data, token));70 }71 await Promise.all(results);72 };73 test('Get with zero elements', async () => {74 const res = await api.get('/posts?page=1&limit=10', token);75 expect(res.status).toBe(OK);76 expect(res.body).toContainEntry(['posts', []]);77 expect(res.body).toContainEntry(['pageCount', 0]);78 expect(res.body).toContainEntry(['itemCount', 0]);79 expect(res.body).toContainEntry(['pages', []]);80 });81 test('Get page 2 of 2', async () => {82 await createPosts(12);83 const res = await api.get('/posts?page=2&limit=10', token);84 expect(res.status).toBe(OK);85 expect(res.body).toHaveProperty('posts');86 expect(res.body.posts.length).toBe(2);87 expect(res.body).toContainEntry(['pageCount', 2]);88 expect(res.body).toContainEntry(['itemCount', 12]);89 expect(res.body).toContainEntry([90 'pages',91 [92 { number: 1, url: '/posts?page=1&limit=10' },93 { number: 2, url: '/posts?page=2&limit=10' },94 ],95 ]);96 });97 test('Get without params', async () => {98 await createPosts(22);99 const res = await api.get('/posts', token);100 expect(res.status).toBe(OK);101 expect(res.body).toHaveProperty('posts');102 expect(res.body.posts.length).toBe(10);103 expect(res.body).toContainEntry(['pageCount', 3]);104 expect(res.body).toContainEntry(['itemCount', 22]);105 expect(res.body).toContainEntry([106 'pages',107 [108 { number: 1, url: '/posts?page=1&limit=10' },109 { number: 2, url: '/posts?page=2&limit=10' },110 { number: 3, url: '/posts?page=3&limit=10' },111 ],112 ]);113 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1expect([['foo', 'bar'], ['baz', 'qux']]).toContainEntry(['foo', 'bar']);2expect([['foo', 'bar'], ['baz', 'qux']]).not.toContainEntry(['foo', 'baz']);3expect(new Map([['foo', 'bar'], ['baz', 'qux']])).toContainEntry(['foo', 'bar']);4expect(new Map([['foo', 'bar'], ['baz', 'qux']])).not.toContainEntry(['foo', 'baz']);5expect(new Set([['foo', 'bar'], ['baz', 'qux']])).toContainEntry(['foo', 'bar']);6expect(new Set([['foo', 'bar'], ['baz', 'qux']])).not.toContainEntry(['foo', 'baz']);7expect(new WeakMap([['foo', 'bar'], ['baz', 'qux']])).toContainEntry(['foo', 'bar']);8expect(new WeakMap([['foo', 'bar'], ['baz', 'qux']])).not.toContainEntry(['foo', 'baz']);9expect(new WeakSet([['foo', 'bar'], ['baz', 'qux']])).toContainEntry(['foo', 'bar']);10expect(new WeakSet([['foo', 'bar'], ['baz', 'qux']])).not.toContainEntry(['foo', 'baz']);11expect(new Map([['foo', 'bar'], ['baz', 'qux']])).toContainEntry(['foo', 'bar']);12expect(new Map([['foo', 'bar'], ['baz', 'qux']])).not.toContainEntry(['foo', 'baz']);13expect(new Set([['foo', 'bar'], ['baz', 'qux']])).toContainEntry(['foo', 'bar']);14expect(new Set([['foo', 'bar'], ['baz', 'qux']])).not.toContainEntry(['foo', 'baz']);15expect(new WeakMap([['foo', 'bar'], ['baz', 'qux']])).toContainEntry(['foo', 'bar']);16expect(new Weak

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toContainEntry } = require('jest-extended');2expect.extend({ toContainEntry });3test('toContainEntry', () => {4 expect(new Map([['a', 1]])).toContainEntry(['a', 1]);5 expect(new Map([['a', 1]])).not.toContainEntry(['a', 2]);6 expect(new Map([['a', 1]])).not.toContainEntry(['b', 1]);7});8const { toContainAllEntries } = require('jest-extended');9expect.extend({ toContainAllEntries });10test('toContainAllEntries', () => {11 expect(new Map([['a', 1], ['b', 2]])).toContainAllEntries([['a', 1]]);12 expect(new Map([['a', 1], ['b', 2]])).toContainAllEntries([['a', 1], ['b', 2]]);13 expect(new Map([['a', 1], ['b', 2]])).not.toContainAllEntries([['a', 2], ['b', 2]]);14});15const { toContainAnyEntries } = require('jest-extended');16expect.extend({ toContainAnyEntries });17test('toContainAnyEntries', () => {18 expect(new Map([['a', 1], ['b', 2]])).toContainAnyEntries([['a', 1]]);19 expect(new Map([['a', 1], ['b', 2]])).toContainAnyEntries([['a', 2], ['b', 2]]);20 expect(new Map([['a', 1], ['b', 2]])).not.toContain

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('toContainEntry', () => {2 it('should pass', () => {3 expect(new Map([['foo', 'bar']])).toContainEntry(['foo', 'bar']);4 expect(new Map([['foo', 'bar']])).not.toContainEntry(['bar', 'foo']);5 });6});7describe('toContainEntries', () => {8 it('should pass', () => {9 expect(new Map([['foo', 'bar'], ['bar', 'foo']])).toContainEntries([10 ]);11 expect(new Map([['foo', 'bar'], ['bar', 'foo']])).not.toContainEntries([12 ]);13 });14});15describe('toContainKey', () => {16 it('should pass', () => {17 expect(new Map([['foo', 'bar']])).toContainKey('foo');18 expect(new Map([['foo', 'bar']])).not.toContainKey('bar');19 });20});21describe('toContainKeys', () => {22 it('should pass', () => {23 expect(new Map([['foo', 'bar'], ['bar', 'foo']])).toContainKeys(['foo', 'bar']);24 expect(new Map([['foo', 'bar'], ['bar', 'foo']])).not.toContainKeys(['foo', 'baz']);25 });26});27describe('toContainValue', () => {28 it('should pass', () => {29 expect(new Map([['foo', 'bar']])).toContainValue('bar');30 expect(new Map([['foo', 'bar']])).not.toContainValue('foo');31 });32});33describe('toContainValues', () => {34 it('should pass', () => {35 expect(new Map([['foo', 'bar'], ['bar', 'foo']])).toContainValues(['bar', 'foo']);36 expect(new Map([['foo', 'bar'], ['bar', 'foo']

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toContainEntry } = require('jest-extended');2expect.extend({ toContainEntry });3test('toContainEntry', () => {4 const obj = { a: 1, b: 2 };5 expect(obj).toContainEntry(['a', 1]);6});7toContainEntry (2ms)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toContainEntry } = require("jest-extended");2expect.extend({ toContainEntry });3const myMap = new Map();4myMap.set("a", 1);5myMap.set("b", 2);6expect(myMap).toContainEntry(["a", 1]);7expect(myMap).toContainEntry(["b", 2]);8expect(myMap).not.toContainEntry(["c", 3]);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toContainEntry } = require('jest-extended')2expect.extend({ toContainEntry })3test('toContainEntry', () => {4 const myMap = new Map()5 myMap.set('a', 1)6 myMap.set('b', 2)7 myMap.set('c', 3)8 expect(myMap).toContainEntry(['a', 1])9 expect(myMap).not.toContainEntry(['a', 2])10})11const { toContainAllEntries } = require('jest-extended')12expect.extend({ toContainAllEntries })13test('toContainAllEntries', () => {14 const myMap = new Map()15 myMap.set('a', 1)16 myMap.set('b', 2)17 myMap.set('c', 3)18 expect(myMap).toContainAllEntries([['a', 1], ['b', 2]])19 expect(myMap).not.toContainAllEntries([['a', 1], ['b', 3]])20})21const { toContainAnyEntries } = require('jest-extended')22expect.extend({ toContainAnyEntries })23test('toContainAnyEntries', () => {24 const myMap = new Map()25 myMap.set('a', 1)26 myMap.set('b', 2)27 myMap.set('c', 3)28 expect(myMap).toContainAnyEntries([['a', 1], ['b', 3]])29 expect(myMap).not.toContainAnyEntries([['d', 4], ['e', 5]])30})31const { toContainAllKeys } = require('jest-extended')32expect.extend({ toContainAllKeys })33test('toContainAllKeys', () => {34 const myMap = new Map()35 myMap.set('a', 1)36 myMap.set('b', 2)37 myMap.set('c', 3)38 expect(myMap).toContainAllKeys(['a', 'b', 'c'])39 expect(myMap).not.toContainAllKeys(['a', 'b', 'd'])40})

Full Screen

Using AI Code Generation

copy

Full Screen

1expect([{ foo: 1 }, { bar: 2 }]).toContainEntry([['foo', 1]]);2expect([{ foo: 1 }, { bar: 2 }]).not.toContainEntry([['foo', 3]]);3expect([{ foo: 1 }, { bar: 2 }]).toContainEntry([['foo', expect.any(Number)]]);4expect([{ foo: 1 }, { bar: 2 }]).not.toContainEntry([['foo', expect.any(String)]]);5expect([{ foo: 1 }, { bar: 2 }]).toContainEntry([['foo', expect.anything()]]);6expect([{ foo: 1 }, { bar: 2 }]).not.toContainEntry([['foo', expect.not.anything()]]);7expect([{ foo: 1 }, { bar: 2 }]).toContainEntry([[expect.any(String), expect.any(Number)]]);8expect([{ foo: 1 }, { bar: 2 }]).not.toContainEntry([[expect.any(String), expect.any(String)]]);9expect([{ foo: 1 }, { bar: 2 }]).toContainEntry([[expect.any(String), expect.anything()]]);10expect([{ foo: 1 }, { bar: 2 }]).not.toContainEntry([[expect.any(String), expect.not.anything()]]);11expect([{ foo: 1 }, { bar: 2 }]).toContainEntry([[expect.any(String), 1]]);12expect([{ foo: 1 }, { bar: 2 }]).not.toContainEntry([[expect.any(String), 3]]);13expect([{ foo: 1 }, { bar: 2 }]).toContainEntry([[expect.any

Full Screen

Using AI Code Generation

copy

Full Screen

1const object = { a: 1, b: 2, c: 3 };2test('object contains entries', () => {3 expect(object).toContainEntry(['a', 1]);4 expect(object).toContainEntry(['b', 2]);5 expect(object).toContainEntry(['c', 3]);6});7const object = { a: 1, b: 2, c: 3 };8test('object contains entries', () => {9 expect(object).toContainEntries([10 ]);11});12const object = { a: 1, b: 2, c: 3 };13test('object contains entries', () => {14 expect(object).toContainAllEntries([15 ]);16});17const object = { a: 1, b: 2, c: 3 };18test('object contains entries', () => {19 expect(object).toContainAnyEntries([20 ]);21});22const object = { a: 1, b: 2, c: 3 };23test('object contains keys', () => {24 expect(object).toContainAnyKeys(['a', 'e']);25 expect(object).toContainAnyKeys(['a', 'b']);26});27const object = { a: 1, b: 2, c: 3 };28test('object contains keys', () => {29 expect(object).toContainAllKeys(['a', 'b']);30});31const object = { a: 1, b: 2, c: 3 };32test('object contains keys', () => {33 expect(object).toContainKey('a');34 expect(object).toContainKey('b');35 expect(object).toContainKey('c');36});37test('array has size', () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toContainEntry } = require('jest-extended');2expect.extend({ toContainEntry });3test('object contains the key value pair', () => {4 expect({ a: 1 }).toContainEntry(['a', 1]);5});6test('object does not contain the key value pair', () => {7 expect({ a: 1 }).not.toContainEntry(['a', 2]);8});9test('object contains the key value pair', () => {10 expect({ a: 1 }).not.toContainEntry(['a', 1], false);11});12test('object does not contain the key value pair', () => {13 expect({ a: 1 }).toContainEntry(['a', 2], false);14});15test('object contains the key value pair', () => {16 expect({ a: 1 }).toContainEntry(['a', 1], true);17});18test('object does not contain the key value pair', () => {19 expect({ a: 1 }).not.toContainEntry(['a', 2], true);20});21test('object contains the key value pair', () => {22 expect({ a: 1 }).toContainEntry(['a', 1], false);23});24test('object does not contain the key value pair', () => {25 expect({ a: 1 }).not.toContainEntry(['a', 2], false);26});27test('object contains the key value pair', () => {28 expect({ a: 1 }).toContainEntry(['a', 1], true);29});30test('object does not contain the key value pair', () => {31 expect({ a: 1 }).not.toContainEntry(['a', 2], true);32});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run jest-extended automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful