Merge pull request 'Bulk card creation feature/168-runnercards_bulk' (#169) from feature/168-runnercards_bulk into dev
continuous-integration/drone/pr Build is passing Details
continuous-integration/drone/push Build is failing Details

Reviewed-on: #169
This commit is contained in:
Nicolai Ort 2021-03-23 17:41:31 +00:00
commit 1dd64204cc
2 changed files with 38 additions and 0 deletions

View File

@ -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. <br> Just provide the count as a query param and wait for the 200 response." })
async postBlancoBulk(@QueryParam("count") count: number) {
let createPromises = new Array<any>();
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)

View File

@ -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");
});
});