From c1bbda51f067cbd9ac1a9a5378ae3f5d7b9f4eca Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 23 Mar 2021 18:16:55 +0100 Subject: [PATCH 1/2] Added new "bulk" endpoint ref #168 --- src/controllers/RunnerCardController.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/controllers/RunnerCardController.ts b/src/controllers/RunnerCardController.ts index ae74e86..c611ef5 100644 --- a/src/controllers/RunnerCardController.ts +++ b/src/controllers/RunnerCardController.ts @@ -47,6 +47,21 @@ export class RunnerCardController { return card.toResponse(); } + @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) { + let createPromises = new Array(); + for (let index = 0; index < count; index++) { + createPromises.push(this.cardRepository.save({ runner: null, enabled: true })) + } + await Promise.all(createPromises); + let response = new ResponseEmpty(); + response.response = `Created ${count} new blanco cards.` + return response; + } + @Post() @Authorized("CARD:CREATE") @ResponseSchema(ResponseRunnerCard) From 438ff0fc3f246f83b1fa04cb11828f4a61dfcd1e Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 23 Mar 2021 18:19:49 +0100 Subject: [PATCH 2/2] Added bulk card creation tests ref #168 --- src/tests/cards/cards_add.spec.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/tests/cards/cards_add.spec.ts b/src/tests/cards/cards_add.spec.ts index 10ee9d4..ef967af 100644 --- a/src/tests/cards/cards_add.spec.ts +++ b/src/tests/cards/cards_add.spec.ts @@ -148,4 +148,27 @@ describe('POST /api/cards successfully (with runner)', () => { "responseType": "RUNNERCARD" }); }); +}); +// --------------- +describe('POST /api/cards/bulk successfully', () => { + it('creating a single new bulk card should return 200', async () => { + const res = await axios.post(base + '/api/cards/bulk?count=1', {}, axios_config); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json"); + }); + 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); + expect(res.headers['content-type']).toContain("application/json"); + }); + 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); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('creating 2000 new bulk card should return 200', async () => { + const res = await axios.post(base + '/api/cards/bulk?count=2000', {}, axios_config); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json"); + }); }); \ No newline at end of file