Added card update tests
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
ref #77
This commit is contained in:
parent
ebf66821a2
commit
35ea3154d1
|
@ -0,0 +1,163 @@
|
|||
import axios from 'axios';
|
||||
import { config } from '../../config';
|
||||
const base = "http://localhost:" + config.internal_port
|
||||
|
||||
let access_token;
|
||||
let axios_config;
|
||||
|
||||
beforeAll(async () => {
|
||||
const res = await axios.post(base + '/api/auth/login', { username: "demo", password: "demo" });
|
||||
access_token = res.data["access_token"];
|
||||
axios_config = {
|
||||
headers: { "authorization": "Bearer " + access_token },
|
||||
validateStatus: undefined
|
||||
};
|
||||
});
|
||||
|
||||
describe('adding + updating illegally', () => {
|
||||
let added_card;
|
||||
it('creating card without runner should return 200', async () => {
|
||||
const res = await axios.post(base + '/api/cards', null, axios_config);
|
||||
added_card = res.data;
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('updating empty should return 400', async () => {
|
||||
const res2 = await axios.put(base + '/api/cards/' + added_card.id, null, axios_config);
|
||||
expect(res2.status).toEqual(400);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('updating with wrong id should return 406', async () => {
|
||||
const res2 = await axios.put(base + '/api/cards/' + added_card.id, {
|
||||
"id": added_card.id + 1
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(406);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('update with invalid runner id should return 404', async () => {
|
||||
const res2 = await axios.put(base + '/api/cards/' + added_card.id, {
|
||||
"id": added_card.id,
|
||||
"runner": 9999999999999999999999999
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(404);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('adding + updating card.runner successfully', () => {
|
||||
let added_org;
|
||||
let added_runner;
|
||||
let added_runner2;
|
||||
let added_card;
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res1.data
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new runner with only needed params should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/runners', {
|
||||
"firstname": "first",
|
||||
"lastname": "last",
|
||||
"group": added_org.id
|
||||
}, axios_config);
|
||||
delete res2.data.group;
|
||||
added_runner = res2.data;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new runner with only needed params should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/runners', {
|
||||
"firstname": "first",
|
||||
"lastname": "last",
|
||||
"group": added_org.id
|
||||
}, axios_config);
|
||||
delete res2.data.group;
|
||||
added_runner2 = res2.data;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating card without runner should return 200', async () => {
|
||||
const res = await axios.post(base + '/api/cards', null, axios_config);
|
||||
added_card = res.data;
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('valid runner update (add runner) should return 200', async () => {
|
||||
const res2 = await axios.put(base + '/api/cards/' + added_card.id, {
|
||||
"id": added_card.id,
|
||||
"runner": added_runner.id
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json");
|
||||
expect(res2.data).toEqual({
|
||||
"id": added_card.id,
|
||||
"runner": added_runner,
|
||||
"enabled": true,
|
||||
"code": added_card.code
|
||||
});
|
||||
});
|
||||
it('valid runner update (change runner) should return 200', async () => {
|
||||
const res2 = await axios.put(base + '/api/cards/' + added_card.id, {
|
||||
"id": added_card.id,
|
||||
"runner": added_runner2.id
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json");
|
||||
expect(res2.data).toEqual({
|
||||
"id": added_card.id,
|
||||
"runner": added_runner2,
|
||||
"enabled": true,
|
||||
"code": added_card.code
|
||||
});
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('adding + updating other values successfully', () => {
|
||||
let added_card;
|
||||
it('creating card without runner should return 200', async () => {
|
||||
const res = await axios.post(base + '/api/cards', null, axios_config);
|
||||
added_card = res.data;
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('valid update changeing nothing should return 200', async () => {
|
||||
const res2 = await axios.put(base + '/api/cards/' + added_card.id, {
|
||||
"id": added_card.id
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json");
|
||||
expect(res2.data).toEqual(added_card);
|
||||
});
|
||||
it('valid disable update should return 200', async () => {
|
||||
const res2 = await axios.put(base + '/api/cards/' + added_card.id, {
|
||||
"id": added_card.id,
|
||||
"enabled": false
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json");
|
||||
expect(res2.data).toEqual({
|
||||
"id": added_card.id,
|
||||
"runner": null,
|
||||
"enabled": false,
|
||||
"code": added_card.code
|
||||
});
|
||||
});
|
||||
it('valid enable update should return 200', async () => {
|
||||
const res2 = await axios.put(base + '/api/cards/' + added_card.id, {
|
||||
"id": added_card.id,
|
||||
"enabled": true
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json");
|
||||
expect(res2.data).toEqual({
|
||||
"id": added_card.id,
|
||||
"runner": null,
|
||||
"enabled": true,
|
||||
"code": added_card.code
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue