From e165f019307e7745357493eacf3e2fa31538122b Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 19 Jan 2021 18:48:37 +0100 Subject: [PATCH] Added contact add valid tests ref #104 --- src/tests/contacts/contact_add.spec.ts | 141 +++++++++++++++++++++++++ 1 file changed, 141 insertions(+) diff --git a/src/tests/contacts/contact_add.spec.ts b/src/tests/contacts/contact_add.spec.ts index 2136aa3..0cb5160 100644 --- a/src/tests/contacts/contact_add.spec.ts +++ b/src/tests/contacts/contact_add.spec.ts @@ -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); + }); +}); \ No newline at end of file