From 5a36c8dcae3d79b3b05ffb30a7ebb0d31dc8183a Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Sun, 28 Mar 2021 18:44:21 +0200 Subject: [PATCH 1/4] Added query param to return created runenrcards ref #180 --- src/controllers/RunnerCardController.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/controllers/RunnerCardController.ts b/src/controllers/RunnerCardController.ts index 808b0d5..84f10eb 100644 --- a/src/controllers/RunnerCardController.ts +++ b/src/controllers/RunnerCardController.ts @@ -50,13 +50,22 @@ export class RunnerCardController { @Post('/bulk') @Authorized("CARD:CREATE") @ResponseSchema(ResponseEmpty, { statusCode: 200 }) - @OpenAPI({ description: "Create blank cards in bulk.
Just provide the count as a query param and wait for the 200 response." }) - async postBlancoBulk(@QueryParam("count") count: number) { + @OpenAPI({ description: "Create blank cards in bulk.
Just provide the count as a query param and wait for the 200 response.
You can provide the 'returnCards' query param if you want to receive the RESPONSERUNNERCARD objects in the response." }) + async postBlancoBulk(@QueryParam("count") count: number, @QueryParam("returnCards") returnCards: boolean = false) { let createPromises = new Array(); for (let index = 0; index < count; index++) { createPromises.push(this.cardRepository.save({ runner: null, enabled: true })) } - await Promise.all(createPromises); + + const cards = await Promise.all(createPromises); + + if (returnCards) { + let responseCards: ResponseRunnerCard[] = new Array(); + cards.forEach(card => { + responseCards.push(new ResponseRunnerCard(card)); + }); + return responseCards; + } let response = new ResponseEmpty(); response.response = `Created ${count} new blanco cards.` return response; -- 2.47.2 From 6005b0661f1d5c461bb102e243cc209a8adc21fa Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Sun, 28 Mar 2021 18:46:25 +0200 Subject: [PATCH 2/4] Added test for single card generation with returnCards=true ref #180 --- src/tests/cards/cards_add.spec.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tests/cards/cards_add.spec.ts b/src/tests/cards/cards_add.spec.ts index 9b13baa..4f63826 100644 --- a/src/tests/cards/cards_add.spec.ts +++ b/src/tests/cards/cards_add.spec.ts @@ -156,6 +156,12 @@ describe('POST /api/cards/bulk successfully', () => { expect(res.status).toEqual(200); expect(res.headers['content-type']).toContain("application/json"); }); + it('creating a single new bulk card and letting the system return it should return 200', async () => { + const res = await axios.post(base + '/api/cards/bulk?count=1&returnCards=true', {}, axios_config); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json"); + expect(res.data[0].id).toBeDefined(); + }); it('creating 50 new bulk card should return 200', async () => { const res = await axios.post(base + '/api/cards/bulk?count=50', {}, axios_config); expect(res.status).toEqual(200); -- 2.47.2 From 1cb2dc9d53b530435f5798f9cdf7ee866eb7416e Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Sun, 28 Mar 2021 18:47:32 +0200 Subject: [PATCH 3/4] Added test for returnCards=true array length ref #180 --- src/tests/cards/cards_add.spec.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tests/cards/cards_add.spec.ts b/src/tests/cards/cards_add.spec.ts index 4f63826..18da63c 100644 --- a/src/tests/cards/cards_add.spec.ts +++ b/src/tests/cards/cards_add.spec.ts @@ -167,6 +167,12 @@ describe('POST /api/cards/bulk successfully', () => { expect(res.status).toEqual(200); expect(res.headers['content-type']).toContain("application/json"); }); + it('creating 50 new bulk cards and letting the system return it should return 200', async () => { + const res = await axios.post(base + '/api/cards/bulk?count=1&returnCards=true', {}, axios_config); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json"); + expect(res.data.length).toEqual(50); + }); it('creating 250 new bulk card should return 200', async () => { const res = await axios.post(base + '/api/cards/bulk?count=250', {}, axios_config); expect(res.status).toEqual(200); -- 2.47.2 From 2f568c9cb8ae39ce40ec8df6d9acbaf0d5ae1a26 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Sun, 28 Mar 2021 18:54:16 +0200 Subject: [PATCH 4/4] Fixed copy-paste oversight ref #180 --- src/tests/cards/cards_add.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/cards/cards_add.spec.ts b/src/tests/cards/cards_add.spec.ts index 18da63c..05d8ace 100644 --- a/src/tests/cards/cards_add.spec.ts +++ b/src/tests/cards/cards_add.spec.ts @@ -168,7 +168,7 @@ describe('POST /api/cards/bulk successfully', () => { expect(res.headers['content-type']).toContain("application/json"); }); it('creating 50 new bulk cards and letting the system return it should return 200', async () => { - const res = await axios.post(base + '/api/cards/bulk?count=1&returnCards=true', {}, axios_config); + const res = await axios.post(base + '/api/cards/bulk?count=50&returnCards=true', {}, axios_config); expect(res.status).toEqual(200); expect(res.headers['content-type']).toContain("application/json"); expect(res.data.length).toEqual(50); -- 2.47.2