Added contact add valid tests

ref #104
This commit is contained in:
Nicolai Ort 2021-01-19 18:48:37 +01:00
parent 940d62cde4
commit e165f01930
1 changed files with 141 additions and 0 deletions

View File

@ -73,3 +73,144 @@ describe('POST /api/contacts with errors', () => {
expect(res.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('POST /api/contacts working (simple)', () => {
it('creating a new contact with only needed params should return 200', async () => {
const res = await axios.post(base + '/api/contacts', {
"firstname": "first",
"lastname": "last"
}, axios_config);
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
it('creating a new contact with all non-relationship optional params should return 200', async () => {
const res = await axios.post(base + '/api/contacts', {
"firstname": "first",
"middlename": "middle",
"lastname": "last",
"email": "testContact@lauf-fuer-kaya.de",
"phone": "+49017612345678",
"address": {
"address1": "test",
"address2": null,
"city": "herzogenaurach",
"country": "germany",
"postalcode": "91074",
}
}, axios_config);
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('POST /api/contacts working (with group)', () => {
let added_org;
let added_team;
let added_contact;
it('creating a new org with just a name should return 200', async () => {
const res = await axios.post(base + '/api/organisations', {
"name": "test123"
}, axios_config);
delete res.data.contact;
delete res.data.teams;
added_org = res.data
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
it('creating a new team with a parent org should return 200', async () => {
const res = await axios.post(base + '/api/teams', {
"name": "test_team",
"parentGroup": added_org.id
}, axios_config);
delete res.data.contact;
delete res.data.parentGroup;
added_team = res.data;
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
it('creating a new contact with a valid org should return 200', async () => {
const res = await axios.post(base + '/api/contacts', {
"firstname": "first",
"lastname": "last",
"groups": added_org.id
}, axios_config);
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json");
delete res.data.id;
expect(res.data).toEqual({
"firstname": "first",
"middlename": null,
"lastname": "last",
"phone": null,
"email": null,
"address": {
"address1": null,
"address2": null,
"postalcode": null,
"city": null,
"country": null
},
"groups": [added_org]
});
});
it('creating a new contact with a valid team should return 200', async () => {
const res = await axios.post(base + '/api/contacts', {
"firstname": "first",
"lastname": "last",
"groups": added_team.id
}, axios_config);
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json");
delete res.data.id;
expect(res.data).toEqual({
"firstname": "first",
"middlename": null,
"lastname": "last",
"phone": null,
"email": null,
"address": {
"address1": null,
"address2": null,
"postalcode": null,
"city": null,
"country": null
},
"groups": [added_team]
});
});
it('creating a new contact with a valid org and team should return 200', async () => {
const res = await axios.post(base + '/api/contacts', {
"firstname": "first",
"lastname": "last",
"groups": [added_org.id, added_team.id]
}, axios_config);
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json");
added_contact = res.data
delete res.data.id;
expect(res.data).toEqual({
"firstname": "first",
"middlename": null,
"lastname": "last",
"phone": null,
"email": null,
"address": {
"address1": null,
"address2": null,
"postalcode": null,
"city": null,
"country": null
},
"groups": [added_org, added_team]
});
});
it('checking if the added team\'s contact is the new contact should return 200', async () => {
const res = await axios.get(base + '/api/teams/' + added_team.id, axios_config);
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json");
delete res.data.contact.groups;
delete res.data.contact.id;
delete added_contact.groups;
expect(res.data.contact).toEqual(added_contact);
});
});