Merge pull request 'Return cards generated in bulk feature/180-blank_generation_return' (#181) from feature/180-blank_generation_return into dev
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
Reviewed-on: #181
This commit is contained in:
commit
0f7fa990d4
|
@ -50,13 +50,22 @@ export class RunnerCardController {
|
||||||
@Post('/bulk')
|
@Post('/bulk')
|
||||||
@Authorized("CARD:CREATE")
|
@Authorized("CARD:CREATE")
|
||||||
@ResponseSchema(ResponseEmpty, { statusCode: 200 })
|
@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." })
|
@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) {
|
async postBlancoBulk(@QueryParam("count") count: number, @QueryParam("returnCards") returnCards: boolean = false) {
|
||||||
let createPromises = new Array<any>();
|
let createPromises = new Array<any>();
|
||||||
for (let index = 0; index < count; index++) {
|
for (let index = 0; index < count; index++) {
|
||||||
createPromises.push(this.cardRepository.save({ runner: null, enabled: true }))
|
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();
|
let response = new ResponseEmpty();
|
||||||
response.response = `Created ${count} new blanco cards.`
|
response.response = `Created ${count} new blanco cards.`
|
||||||
return response;
|
return response;
|
||||||
|
|
|
@ -156,11 +156,23 @@ describe('POST /api/cards/bulk successfully', () => {
|
||||||
expect(res.status).toEqual(200);
|
expect(res.status).toEqual(200);
|
||||||
expect(res.headers['content-type']).toContain("application/json");
|
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 () => {
|
it('creating 50 new bulk card should return 200', async () => {
|
||||||
const res = await axios.post(base + '/api/cards/bulk?count=50', {}, axios_config);
|
const res = await axios.post(base + '/api/cards/bulk?count=50', {}, axios_config);
|
||||||
expect(res.status).toEqual(200);
|
expect(res.status).toEqual(200);
|
||||||
expect(res.headers['content-type']).toContain("application/json");
|
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 () => {
|
it('creating 250 new bulk card should return 200', async () => {
|
||||||
const res = await axios.post(base + '/api/cards/bulk?count=250', {}, axios_config);
|
const res = await axios.post(base + '/api/cards/bulk?count=250', {}, axios_config);
|
||||||
expect(res.status).toEqual(200);
|
expect(res.status).toEqual(200);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user