Added contact add invalid tests

ref #104
This commit is contained in:
Nicolai Ort 2021-01-19 18:14:09 +01:00
parent b002cf2df1
commit 940d62cde4
1 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,75 @@
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('POST /api/contacts with errors', () => {
it('creating a new contact without any parameters should return 400', async () => {
const res = await axios.post(base + '/api/contacts', null, axios_config);
expect(res.status).toEqual(400);
expect(res.headers['content-type']).toContain("application/json")
});
it('creating a new contact without a last name should return 400', async () => {
const res = await axios.post(base + '/api/contacts', {
"firstname": "first",
"middlename": "middle"
}, axios_config);
expect(res.status).toEqual(400);
expect(res.headers['content-type']).toContain("application/json")
});
it('creating a new contact with a invalid phone number should return 400', async () => {
const res = await axios.post(base + '/api/contacts', {
"firstname": "first",
"middlename": "middle",
"lastname": "last",
"phone": "123"
}, axios_config);
expect(res.status).toEqual(400);
expect(res.headers['content-type']).toContain("application/json")
});
it('creating a new contact with a invalid mail address should return 400', async () => {
const res = await axios.post(base + '/api/contacts', {
"firstname": "string",
"middlename": "string",
"lastname": "string",
"phone": null,
"email": "123",
}, axios_config);
expect(res.status).toEqual(400);
expect(res.headers['content-type']).toContain("application/json")
});
it('creating a new contact with an invalid address 400', async () => {
const res = await axios.post(base + '/api/contacts', {
"firstname": "string",
"middlename": "string",
"lastname": "string",
"address": {
"city": "Testcity"
}
}, axios_config);
expect(res.status).toEqual(400);
expect(res.headers['content-type']).toContain("application/json")
});
it('creating a new contact with a invalid group should return 404', async () => {
const res = await axios.post(base + '/api/contacts', {
"firstname": "string",
"middlename": "string",
"lastname": "string",
"groups": 9999999999999
}, axios_config);
expect(res.status).toEqual(404);
expect(res.headers['content-type']).toContain("application/json")
});
});