Merge pull request 'Return cards generated in bulk feature/180-blank_generation_return' (#181) from feature/180-blank_generation_return into dev
continuous-integration/drone/push Build is failing Details

Reviewed-on: #181
This commit is contained in:
Nicolai Ort 2021-03-29 15:48:05 +00:00
commit 0f7fa990d4
2 changed files with 24 additions and 3 deletions

View File

@ -50,13 +50,22 @@ export class RunnerCardController {
@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) {
@OpenAPI({ description: "Create blank cards in bulk. <br> Just provide the count as a query param and wait for the 200 response. <br> 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<any>();
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<ResponseRunnerCard>();
cards.forEach(card => {
responseCards.push(new ResponseRunnerCard(card));
});
return responseCards;
}
let response = new ResponseEmpty();
response.response = `Created ${count} new blanco cards.`
return response;

View File

@ -156,11 +156,23 @@ 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);
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=50&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);