Merge pull request 'Release v0.9.1' (#182) from dev into main
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

Reviewed-on: #182
Reviewed-by: Philipp Dormann <philipp@philippdormann.de>
This commit is contained in:
Nicolai Ort 2021-03-29 16:12:14 +00:00
commit 3afd785a54
4 changed files with 334 additions and 298 deletions

View File

@ -2,8 +2,22 @@
All notable changes to this project will be documented in this file. Dates are displayed in UTC. All notable changes to this project will be documented in this file. Dates are displayed in UTC.
#### [v0.9.1](https://git.odit.services/lfk/backend/compare/v0.9.0...v0.9.1)
- 🚀Bumped version to v0.9.1 [`a139554`](https://git.odit.services/lfk/backend/commit/a139554e059e9a10acb1733ce1a82b610cc99269)
- Added query param to return created runenrcards [`5a36c8d`](https://git.odit.services/lfk/backend/commit/5a36c8dcae3d79b3b05ffb30a7ebb0d31dc8183a)
- 🧾New changelog file version [CI SKIP] [skip ci] [`0290b0e`](https://git.odit.services/lfk/backend/commit/0290b0e5f531364d37d8157e639614cf5a6b4189)
- Merge pull request 'Return cards generated in bulk feature/180-blank_generation_return' (#181) from feature/180-blank_generation_return into dev [`0f7fa99`](https://git.odit.services/lfk/backend/commit/0f7fa990d473ce2dce032c47c39f79c1d0e8df90)
- 🧾New changelog file version [CI SKIP] [skip ci] [`58f4d21`](https://git.odit.services/lfk/backend/commit/58f4d2151f459bc72692cc70e02a59b77abfb9f0)
- Added test for returnCards=true array length [`1cb2dc9`](https://git.odit.services/lfk/backend/commit/1cb2dc9d53b530435f5798f9cdf7ee866eb7416e)
- Added test for single card generation with returnCards=true [`6005b06`](https://git.odit.services/lfk/backend/commit/6005b0661f1d5c461bb102e243cc209a8adc21fa)
- Fixed copy-paste oversight [`2f568c9`](https://git.odit.services/lfk/backend/commit/2f568c9cb8ae39ce40ec8df6d9acbaf0d5ae1a26)
#### [v0.9.0](https://git.odit.services/lfk/backend/compare/v0.8.0...v0.9.0) #### [v0.9.0](https://git.odit.services/lfk/backend/compare/v0.8.0...v0.9.0)
> 26 March 2021
- Merge pull request 'Release 0.9.0' (#179) from dev into main [`95135dd`](https://git.odit.services/lfk/backend/commit/95135ddc893dcf64be67b47b0ef2b0d9041253bd)
- Reenabled user tests [`4c66650`](https://git.odit.services/lfk/backend/commit/4c6665062fe6717242e43b58e66c1f1d030c018d) - Reenabled user tests [`4c66650`](https://git.odit.services/lfk/backend/commit/4c6665062fe6717242e43b58e66c1f1d030c018d)
- Moved to tmp files to better check for other problems [`7a64f23`](https://git.odit.services/lfk/backend/commit/7a64f2393783f97a9729356bc1dfd831927dd312) - Moved to tmp files to better check for other problems [`7a64f23`](https://git.odit.services/lfk/backend/commit/7a64f2393783f97a9729356bc1dfd831927dd312)
- Added user creation invalid tests [`888cab5`](https://git.odit.services/lfk/backend/commit/888cab5898caf9e552c421346934bf90f717a653) - Added user creation invalid tests [`888cab5`](https://git.odit.services/lfk/backend/commit/888cab5898caf9e552c421346934bf90f717a653)
@ -15,16 +29,17 @@ All notable changes to this project will be documented in this file. Dates are d
- 🧾New changelog file version [CI SKIP] [skip ci] [`274a146`](https://git.odit.services/lfk/backend/commit/274a146b9bccfe5e1a879ca137ebb4f51eaa5d57) - 🧾New changelog file version [CI SKIP] [skip ci] [`274a146`](https://git.odit.services/lfk/backend/commit/274a146b9bccfe5e1a879ca137ebb4f51eaa5d57)
- Fixed test params [`070560e`](https://git.odit.services/lfk/backend/commit/070560e8632e833dd26505c02ccb2474462b63ac) - Fixed test params [`070560e`](https://git.odit.services/lfk/backend/commit/070560e8632e833dd26505c02ccb2474462b63ac)
- No longer using createuser in seeding process [`96ba25e`](https://git.odit.services/lfk/backend/commit/96ba25ec6c6c397cd2aa322afa79024395f658fe) - No longer using createuser in seeding process [`96ba25e`](https://git.odit.services/lfk/backend/commit/96ba25ec6c6c397cd2aa322afa79024395f658fe)
- 🧾New changelog file version [CI SKIP] [skip ci] [`a7fe1e1`](https://git.odit.services/lfk/backend/commit/a7fe1e175918edd7a98983ece570b47075e85e9a)
- 🚀Bumped version to v0.8.0 [`c23b4d9`](https://git.odit.services/lfk/backend/commit/c23b4d907f20ed7af37a6de6ea4c61433e30b29b)
- 🚀Bumped version to v0.9.0 [`56a5f41`](https://git.odit.services/lfk/backend/commit/56a5f4168621263daeab5d2fda97b944cdc6ab31)
- Merge pull request 'Password security feature/99-password_checks' (#177) from feature/99-password_checks into dev [`5a3fc5b`](https://git.odit.services/lfk/backend/commit/5a3fc5b2bd06b3e26177d017d3503f4f627be3f2)
- Added pw errors to user controller [`b24e24f`](https://git.odit.services/lfk/backend/commit/b24e24ff7dd75d972cdab0fd1e2fe6c532ca2b2f) - Added pw errors to user controller [`b24e24f`](https://git.odit.services/lfk/backend/commit/b24e24ff7dd75d972cdab0fd1e2fe6c532ca2b2f)
- Now checking password rules on user creation [`5daaa3a`](https://git.odit.services/lfk/backend/commit/5daaa3a73c4eca2817d67e226679d125928a3645) - Now checking password rules on user creation [`5daaa3a`](https://git.odit.services/lfk/backend/commit/5daaa3a73c4eca2817d67e226679d125928a3645)
- Now checking password rules on user update [`48a87e8`](https://git.odit.services/lfk/backend/commit/48a87e8936e13c48f4baa3f4b10f781ad2f55a44) - Now checking password rules on user update [`48a87e8`](https://git.odit.services/lfk/backend/commit/48a87e8936e13c48f4baa3f4b10f781ad2f55a44)
- Fixed pw not getting hashed currectly; [`cb3ea9b`](https://git.odit.services/lfk/backend/commit/cb3ea9b1ebb82c650abd83d4be8629cfe29a5b21) - Fixed pw not getting hashed currectly; [`cb3ea9b`](https://git.odit.services/lfk/backend/commit/cb3ea9b1ebb82c650abd83d4be8629cfe29a5b21)
- Added pw errors to me controller [`9ce35d8`](https://git.odit.services/lfk/backend/commit/9ce35d8eb78a01f40af8c70e640eca3bcb142304) - Added pw errors to me controller [`9ce35d8`](https://git.odit.services/lfk/backend/commit/9ce35d8eb78a01f40af8c70e640eca3bcb142304)
- 🚀Bumped version to v0.8.0 [`c23b4d9`](https://git.odit.services/lfk/backend/commit/c23b4d907f20ed7af37a6de6ea4c61433e30b29b)
- Added password checker dependency [`bd00f4f`](https://git.odit.services/lfk/backend/commit/bd00f4f8d585fb6878874810f7de0b8b9f3950d5)
- 🚀Bumped version to v0.9.0 [`56a5f41`](https://git.odit.services/lfk/backend/commit/56a5f4168621263daeab5d2fda97b944cdc6ab31)
- Merge pull request 'Password security feature/99-password_checks' (#177) from feature/99-password_checks into dev [`5a3fc5b`](https://git.odit.services/lfk/backend/commit/5a3fc5b2bd06b3e26177d017d3503f4f627be3f2)
- Now forceing user deletion in tests [`8154e71`](https://git.odit.services/lfk/backend/commit/8154e715bbf18938bd5d1031656a88d39231fa81) - Now forceing user deletion in tests [`8154e71`](https://git.odit.services/lfk/backend/commit/8154e715bbf18938bd5d1031656a88d39231fa81)
- Added password checker dependency [`bd00f4f`](https://git.odit.services/lfk/backend/commit/bd00f4f8d585fb6878874810f7de0b8b9f3950d5)
- Fixed empty object getting called [`5369000`](https://git.odit.services/lfk/backend/commit/536900091afd7366128f21058490d0d4f15c6c89) - Fixed empty object getting called [`5369000`](https://git.odit.services/lfk/backend/commit/536900091afd7366128f21058490d0d4f15c6c89)
- 🧾New changelog file version [CI SKIP] [skip ci] [`03d76e6`](https://git.odit.services/lfk/backend/commit/03d76e6d0bc5b4655f7f441232681c9462815526) - 🧾New changelog file version [CI SKIP] [skip ci] [`03d76e6`](https://git.odit.services/lfk/backend/commit/03d76e6d0bc5b4655f7f441232681c9462815526)
- Formatting [`b8c28eb`](https://git.odit.services/lfk/backend/commit/b8c28ebb0808395218b5fb9031f477ae1d48e65e) - Formatting [`b8c28eb`](https://git.odit.services/lfk/backend/commit/b8c28ebb0808395218b5fb9031f477ae1d48e65e)

View File

@ -1,6 +1,6 @@
{ {
"name": "@odit/lfk-backend", "name": "@odit/lfk-backend",
"version": "0.9.0", "version": "0.9.1",
"main": "src/app.ts", "main": "src/app.ts",
"repository": "https://git.odit.services/lfk/backend", "repository": "https://git.odit.services/lfk/backend",
"author": { "author": {

View File

@ -1,121 +1,130 @@
import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers'; import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers';
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
import { getConnectionManager, Repository } from 'typeorm'; import { getConnectionManager, Repository } from 'typeorm';
import { RunnerCardHasScansError, RunnerCardIdsNotMatchingError, RunnerCardNotFoundError } from '../errors/RunnerCardErrors'; import { RunnerCardHasScansError, RunnerCardIdsNotMatchingError, RunnerCardNotFoundError } from '../errors/RunnerCardErrors';
import { RunnerNotFoundError } from '../errors/RunnerErrors'; import { RunnerNotFoundError } from '../errors/RunnerErrors';
import { CreateRunnerCard } from '../models/actions/create/CreateRunnerCard'; import { CreateRunnerCard } from '../models/actions/create/CreateRunnerCard';
import { UpdateRunnerCard } from '../models/actions/update/UpdateRunnerCard'; import { UpdateRunnerCard } from '../models/actions/update/UpdateRunnerCard';
import { RunnerCard } from '../models/entities/RunnerCard'; import { RunnerCard } from '../models/entities/RunnerCard';
import { ResponseEmpty } from '../models/responses/ResponseEmpty'; import { ResponseEmpty } from '../models/responses/ResponseEmpty';
import { ResponseRunnerCard } from '../models/responses/ResponseRunnerCard'; import { ResponseRunnerCard } from '../models/responses/ResponseRunnerCard';
import { ScanController } from './ScanController'; import { ScanController } from './ScanController';
@JsonController('/cards') @JsonController('/cards')
@OpenAPI({ security: [{ "AuthToken": [] }, { "RefreshTokenCookie": [] }] }) @OpenAPI({ security: [{ "AuthToken": [] }, { "RefreshTokenCookie": [] }] })
export class RunnerCardController { export class RunnerCardController {
private cardRepository: Repository<RunnerCard>; private cardRepository: Repository<RunnerCard>;
/** /**
* Gets the repository of this controller's model/entity. * Gets the repository of this controller's model/entity.
*/ */
constructor() { constructor() {
this.cardRepository = getConnectionManager().get().getRepository(RunnerCard); this.cardRepository = getConnectionManager().get().getRepository(RunnerCard);
} }
@Get() @Get()
@Authorized("CARD:GET") @Authorized("CARD:GET")
@ResponseSchema(ResponseRunnerCard, { isArray: true }) @ResponseSchema(ResponseRunnerCard, { isArray: true })
@OpenAPI({ description: 'Lists all card.' }) @OpenAPI({ description: 'Lists all card.' })
async getAll() { async getAll() {
let responseCards: ResponseRunnerCard[] = new Array<ResponseRunnerCard>(); let responseCards: ResponseRunnerCard[] = new Array<ResponseRunnerCard>();
const cards = await this.cardRepository.find({ relations: ['runner', 'runner.group', 'runner.group.parentGroup'] }); const cards = await this.cardRepository.find({ relations: ['runner', 'runner.group', 'runner.group.parentGroup'] });
cards.forEach(card => { cards.forEach(card => {
responseCards.push(new ResponseRunnerCard(card)); responseCards.push(new ResponseRunnerCard(card));
}); });
return responseCards; return responseCards;
} }
@Get('/:id') @Get('/:id')
@Authorized("CARD:GET") @Authorized("CARD:GET")
@ResponseSchema(ResponseRunnerCard) @ResponseSchema(ResponseRunnerCard)
@ResponseSchema(RunnerCardNotFoundError, { statusCode: 404 }) @ResponseSchema(RunnerCardNotFoundError, { statusCode: 404 })
@OnUndefined(RunnerCardNotFoundError) @OnUndefined(RunnerCardNotFoundError)
@OpenAPI({ description: "Lists all information about the card whose id got provided." }) @OpenAPI({ description: "Lists all information about the card whose id got provided." })
async getOne(@Param('id') id: number) { async getOne(@Param('id') id: number) {
let card = await this.cardRepository.findOne({ id: id }, { relations: ['runner', 'runner.group', 'runner.group.parentGroup'] }); let card = await this.cardRepository.findOne({ id: id }, { relations: ['runner', 'runner.group', 'runner.group.parentGroup'] });
if (!card) { throw new RunnerCardNotFoundError(); } if (!card) { throw new RunnerCardNotFoundError(); }
return card.toResponse(); return card.toResponse();
} }
@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);
let response = new ResponseEmpty(); const cards = await Promise.all(createPromises);
response.response = `Created ${count} new blanco cards.`
return response; if (returnCards) {
} let responseCards: ResponseRunnerCard[] = new Array<ResponseRunnerCard>();
cards.forEach(card => {
@Post() responseCards.push(new ResponseRunnerCard(card));
@Authorized("CARD:CREATE") });
@ResponseSchema(ResponseRunnerCard) return responseCards;
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 }) }
@OpenAPI({ description: "Create a new card. <br> You can provide a associated runner by id but you don't have to." }) let response = new ResponseEmpty();
async post(@Body({ validate: true }) createCard: CreateRunnerCard) { response.response = `Created ${count} new blanco cards.`
let card = await createCard.toEntity(); return response;
card = await this.cardRepository.save(card); }
return (await this.cardRepository.findOne({ id: card.id }, { relations: ['runner', 'runner.group', 'runner.group.parentGroup'] })).toResponse();
} @Post()
@Authorized("CARD:CREATE")
@Put('/:id') @ResponseSchema(ResponseRunnerCard)
@Authorized("CARD:UPDATE") @ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
@ResponseSchema(ResponseRunnerCard) @OpenAPI({ description: "Create a new card. <br> You can provide a associated runner by id but you don't have to." })
@ResponseSchema(RunnerCardNotFoundError, { statusCode: 404 }) async post(@Body({ validate: true }) createCard: CreateRunnerCard) {
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 }) let card = await createCard.toEntity();
@ResponseSchema(RunnerCardIdsNotMatchingError, { statusCode: 406 }) card = await this.cardRepository.save(card);
@OpenAPI({ description: "Update the card whose id you provided. <br> Scans created via this card will still be associated with the old runner. <br> Please remember that ids can't be changed." }) return (await this.cardRepository.findOne({ id: card.id }, { relations: ['runner', 'runner.group', 'runner.group.parentGroup'] })).toResponse();
async put(@Param('id') id: number, @Body({ validate: true }) card: UpdateRunnerCard) { }
let oldCard = await this.cardRepository.findOne({ id: id });
@Put('/:id')
if (!oldCard) { @Authorized("CARD:UPDATE")
throw new RunnerCardNotFoundError(); @ResponseSchema(ResponseRunnerCard)
} @ResponseSchema(RunnerCardNotFoundError, { statusCode: 404 })
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
if (oldCard.id != card.id) { @ResponseSchema(RunnerCardIdsNotMatchingError, { statusCode: 406 })
throw new RunnerCardIdsNotMatchingError(); @OpenAPI({ description: "Update the card whose id you provided. <br> Scans created via this card will still be associated with the old runner. <br> Please remember that ids can't be changed." })
} async put(@Param('id') id: number, @Body({ validate: true }) card: UpdateRunnerCard) {
let oldCard = await this.cardRepository.findOne({ id: id });
await this.cardRepository.save(await card.update(oldCard));
return (await this.cardRepository.findOne({ id: id }, { relations: ['runner', 'runner.group', 'runner.group.parentGroup'] })).toResponse(); if (!oldCard) {
} throw new RunnerCardNotFoundError();
}
@Delete('/:id')
@Authorized("CARD:DELETE") if (oldCard.id != card.id) {
@ResponseSchema(ResponseRunnerCard) throw new RunnerCardIdsNotMatchingError();
@ResponseSchema(ResponseEmpty, { statusCode: 204 }) }
@ResponseSchema(RunnerCardHasScansError, { statusCode: 406 })
@OnUndefined(204) await this.cardRepository.save(await card.update(oldCard));
@OpenAPI({ description: "Delete the card whose id you provided. <br> If no card with this id exists it will just return 204(no content). <br> If the card still has scans associated you have to provide the force=true query param (warning: this deletes all scans associated with by this card - please disable it instead or just remove the runner association)." }) return (await this.cardRepository.findOne({ id: id }, { relations: ['runner', 'runner.group', 'runner.group.parentGroup'] })).toResponse();
async remove(@Param("id") id: number, @QueryParam("force") force: boolean) { }
let card = await this.cardRepository.findOne({ id: id });
if (!card) { return null; } @Delete('/:id')
@Authorized("CARD:DELETE")
const cardScans = (await this.cardRepository.findOne({ id: id }, { relations: ["scans"] })).scans; @ResponseSchema(ResponseRunnerCard)
if (cardScans.length != 0 && !force) { @ResponseSchema(ResponseEmpty, { statusCode: 204 })
throw new RunnerCardHasScansError(); @ResponseSchema(RunnerCardHasScansError, { statusCode: 406 })
} @OnUndefined(204)
const scanController = new ScanController; @OpenAPI({ description: "Delete the card whose id you provided. <br> If no card with this id exists it will just return 204(no content). <br> If the card still has scans associated you have to provide the force=true query param (warning: this deletes all scans associated with by this card - please disable it instead or just remove the runner association)." })
for (let scan of cardScans) { async remove(@Param("id") id: number, @QueryParam("force") force: boolean) {
await scanController.remove(scan.id, force); let card = await this.cardRepository.findOne({ id: id });
} if (!card) { return null; }
await this.cardRepository.delete(card); const cardScans = (await this.cardRepository.findOne({ id: id }, { relations: ["scans"] })).scans;
return card.toResponse(); if (cardScans.length != 0 && !force) {
} throw new RunnerCardHasScansError();
}
const scanController = new ScanController;
for (let scan of cardScans) {
await scanController.remove(scan.id, force);
}
await this.cardRepository.delete(card);
return card.toResponse();
}
} }

View File

@ -1,174 +1,186 @@
import axios from 'axios'; import axios from 'axios';
import { config } from '../../config'; import { config } from '../../config';
const base = "http://localhost:" + config.internal_port const base = "http://localhost:" + config.internal_port
let access_token; let access_token;
let axios_config; let axios_config;
beforeAll(async () => { beforeAll(async () => {
jest.setTimeout(20000); jest.setTimeout(20000);
const res = await axios.post(base + '/api/auth/login', { username: "demo", password: "demo" }); const res = await axios.post(base + '/api/auth/login', { username: "demo", password: "demo" });
access_token = res.data["access_token"]; access_token = res.data["access_token"];
axios_config = { axios_config = {
headers: { "authorization": "Bearer " + access_token }, headers: { "authorization": "Bearer " + access_token },
validateStatus: undefined validateStatus: undefined
}; };
}); });
describe('POST /api/cards illegally', () => { describe('POST /api/cards illegally', () => {
it('non-existant runner input should return 404', async () => { it('non-existant runner input should return 404', async () => {
const res = await axios.post(base + '/api/cards', { const res = await axios.post(base + '/api/cards', {
"runner": 999999999999999999999999 "runner": 999999999999999999999999
}, axios_config); }, axios_config);
expect(res.status).toEqual(404); expect(res.status).toEqual(404);
expect(res.headers['content-type']).toContain("application/json") expect(res.headers['content-type']).toContain("application/json")
}); });
}); });
// --------------- // ---------------
describe('POST /api/cards successfully (without runner)', () => { describe('POST /api/cards successfully (without runner)', () => {
it('creating a card with the minimum amount of parameters should return 200', async () => { it('creating a card with the minimum amount of parameters should return 200', async () => {
const res = await axios.post(base + '/api/cards', null, axios_config); const res = await axios.post(base + '/api/cards', null, 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");
delete res.data.id; delete res.data.id;
delete res.data.code; delete res.data.code;
expect(res.data).toEqual({ expect(res.data).toEqual({
"runner": null, "runner": null,
"enabled": true, "enabled": true,
"responseType": "RUNNERCARD" "responseType": "RUNNERCARD"
}); });
}); });
it('creating a disabled card should return 200', async () => { it('creating a disabled card should return 200', async () => {
const res = await axios.post(base + '/api/cards', { const res = await axios.post(base + '/api/cards', {
"enabled": false "enabled": false
}, axios_config); }, 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");
delete res.data.id; delete res.data.id;
delete res.data.code; delete res.data.code;
expect(res.data).toEqual({ expect(res.data).toEqual({
"runner": null, "runner": null,
"enabled": false, "enabled": false,
"responseType": "RUNNERCARD" "responseType": "RUNNERCARD"
}); });
}); });
it('creating a enabled card should return 200', async () => { it('creating a enabled card should return 200', async () => {
const res = await axios.post(base + '/api/cards', { const res = await axios.post(base + '/api/cards', {
"enabled": true "enabled": true
}, axios_config); }, 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");
delete res.data.id; delete res.data.id;
delete res.data.code; delete res.data.code;
expect(res.data).toEqual({ expect(res.data).toEqual({
"runner": null, "runner": null,
"enabled": true, "enabled": true,
"responseType": "RUNNERCARD" "responseType": "RUNNERCARD"
}); });
}); });
}); });
// --------------- // ---------------
describe('POST /api/cards successfully (with runner)', () => { describe('POST /api/cards successfully (with runner)', () => {
let added_org; let added_org;
let added_runner; let added_runner;
it('creating a new org with just a name should return 200', async () => { it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organizations', { const res1 = await axios.post(base + '/api/organizations', {
"name": "test123" "name": "test123"
}, axios_config); }, axios_config);
added_org = res1.data added_org = res1.data
expect(res1.status).toEqual(200); expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json") expect(res1.headers['content-type']).toContain("application/json")
}); });
it('creating a new runner with only needed params should return 200', async () => { it('creating a new runner with only needed params should return 200', async () => {
const res2 = await axios.post(base + '/api/runners', { const res2 = await axios.post(base + '/api/runners', {
"firstname": "first", "firstname": "first",
"lastname": "last", "lastname": "last",
"group": added_org.id "group": added_org.id
}, axios_config); }, axios_config);
added_runner = res2.data; added_runner = res2.data;
expect(res2.status).toEqual(200); expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json") expect(res2.headers['content-type']).toContain("application/json")
}); });
it('creating a card with the minimum amount of parameters should return 200', async () => { it('creating a card with the minimum amount of parameters should return 200', async () => {
const res = await axios.post(base + '/api/cards', { const res = await axios.post(base + '/api/cards', {
"runner": added_runner.id "runner": added_runner.id
}, axios_config); }, 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");
delete res.data.id; delete res.data.id;
delete res.data.code; delete res.data.code;
expect(res.data).toEqual({ expect(res.data).toEqual({
"runner": added_runner, "runner": added_runner,
"enabled": true, "enabled": true,
"responseType": "RUNNERCARD" "responseType": "RUNNERCARD"
}); });
}); });
it('creating a card with runner (no optional params) should return 200', async () => { it('creating a card with runner (no optional params) should return 200', async () => {
const res = await axios.post(base + '/api/cards', { const res = await axios.post(base + '/api/cards', {
"runner": added_runner.id "runner": added_runner.id
}, axios_config); }, 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");
delete res.data.id; delete res.data.id;
delete res.data.code; delete res.data.code;
expect(res.data).toEqual({ expect(res.data).toEqual({
"runner": added_runner, "runner": added_runner,
"enabled": true, "enabled": true,
"responseType": "RUNNERCARD" "responseType": "RUNNERCARD"
}); });
}); });
it('creating a enabled card with runner should return 200', async () => { it('creating a enabled card with runner should return 200', async () => {
const res = await axios.post(base + '/api/cards', { const res = await axios.post(base + '/api/cards', {
"runner": added_runner.id, "runner": added_runner.id,
"enabled": true "enabled": true
}, axios_config); }, 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");
delete res.data.id; delete res.data.id;
delete res.data.code; delete res.data.code;
expect(res.data).toEqual({ expect(res.data).toEqual({
"runner": added_runner, "runner": added_runner,
"enabled": true, "enabled": true,
"responseType": "RUNNERCARD" "responseType": "RUNNERCARD"
}); });
}); });
it('creating a disabled card with runner should return 200', async () => { it('creating a disabled card with runner should return 200', async () => {
const res = await axios.post(base + '/api/cards', { const res = await axios.post(base + '/api/cards', {
"runner": added_runner.id, "runner": added_runner.id,
"enabled": false "enabled": false
}, axios_config); }, 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");
delete res.data.id; delete res.data.id;
delete res.data.code; delete res.data.code;
expect(res.data).toEqual({ expect(res.data).toEqual({
"runner": added_runner, "runner": added_runner,
"enabled": false, "enabled": false,
"responseType": "RUNNERCARD" "responseType": "RUNNERCARD"
}); });
}); });
}); });
// --------------- // ---------------
describe('POST /api/cards/bulk successfully', () => { describe('POST /api/cards/bulk successfully', () => {
it('creating a single new bulk card should return 200', async () => { it('creating a single new bulk card should return 200', async () => {
const res = await axios.post(base + '/api/cards/bulk?count=1', {}, axios_config); const res = await axios.post(base + '/api/cards/bulk?count=1', {}, 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 card should return 200', async () => { 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=50', {}, axios_config); const res = await axios.post(base + '/api/cards/bulk?count=1&returnCards=true', {}, 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");
}); expect(res.data[0].id).toBeDefined();
it('creating 250 new bulk card should return 200', async () => { });
const res = await axios.post(base + '/api/cards/bulk?count=250', {}, axios_config); it('creating 50 new bulk card should return 200', async () => {
expect(res.status).toEqual(200); const res = await axios.post(base + '/api/cards/bulk?count=50', {}, axios_config);
expect(res.headers['content-type']).toContain("application/json"); 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); it('creating 50 new bulk cards and letting the system return it should return 200', async () => {
expect(res.status).toEqual(200); const res = await axios.post(base + '/api/cards/bulk?count=50&returnCards=true', {}, axios_config);
expect(res.headers['content-type']).toContain("application/json"); 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);
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");
});
}); });