Fixed tests testing for a old responseclass

ref #112
This commit is contained in:
Nicolai Ort 2021-01-21 20:01:44 +01:00
parent 6469e3bc97
commit 45c8bb83be
3 changed files with 6 additions and 7 deletions

View File

@ -28,7 +28,7 @@ export class GroupContactController {
@OpenAPI({ description: 'Lists all contacts. <br> This includes the contact\'s associated groups.' }) @OpenAPI({ description: 'Lists all contacts. <br> This includes the contact\'s associated groups.' })
async getAll() { async getAll() {
let responseContacts: ResponseGroupContact[] = new Array<ResponseGroupContact>(); let responseContacts: ResponseGroupContact[] = new Array<ResponseGroupContact>();
const contacts = await this.contactRepository.find({ relations: ['groups'] }); const contacts = await this.contactRepository.find({ relations: ['groups', 'groups.parentGroup'] });
contacts.forEach(contact => { contacts.forEach(contact => {
responseContacts.push(contact.toResponse()); responseContacts.push(contact.toResponse());
}); });
@ -42,7 +42,7 @@ export class GroupContactController {
@OnUndefined(GroupContactNotFoundError) @OnUndefined(GroupContactNotFoundError)
@OpenAPI({ description: 'Lists all information about the contact whose id got provided. <br> This includes the contact\'s associated groups.' }) @OpenAPI({ description: 'Lists all information about the contact whose id got provided. <br> This includes the contact\'s associated groups.' })
async getOne(@Param('id') id: number) { async getOne(@Param('id') id: number) {
let contact = await this.contactRepository.findOne({ id: id }, { relations: ['groups'] }) let contact = await this.contactRepository.findOne({ id: id }, { relations: ['groups', 'groups.parentGroup'] })
if (!contact) { throw new GroupContactNotFoundError(); } if (!contact) { throw new GroupContactNotFoundError(); }
return contact.toResponse(); return contact.toResponse();
} }
@ -61,7 +61,7 @@ export class GroupContactController {
} }
contact = await this.contactRepository.save(contact) contact = await this.contactRepository.save(contact)
return (await this.contactRepository.findOne({ id: contact.id }, { relations: ['groups'] })).toResponse(); return (await this.contactRepository.findOne({ id: contact.id }, { relations: ['groups', 'groups.parentGroup'] })).toResponse();
} }
@Put('/:id') @Put('/:id')
@ -83,7 +83,7 @@ export class GroupContactController {
} }
await this.contactRepository.save(await contact.update(oldContact)); await this.contactRepository.save(await contact.update(oldContact));
return (await this.contactRepository.findOne({ id: contact.id }, { relations: ['groups'] })).toResponse(); return (await this.contactRepository.findOne({ id: contact.id }, { relations: ['groups', 'groups.parentGroup'] })).toResponse();
} }
@Delete('/:id') @Delete('/:id')
@ -95,7 +95,7 @@ export class GroupContactController {
async remove(@Param("id") id: number, @QueryParam("force") force: boolean) { async remove(@Param("id") id: number, @QueryParam("force") force: boolean) {
let contact = await this.contactRepository.findOne({ id: id }); let contact = await this.contactRepository.findOne({ id: id });
if (!contact) { return null; } if (!contact) { return null; }
const responseContact = await this.contactRepository.findOne(contact, { relations: ['groups'] }); const responseContact = await this.contactRepository.findOne(contact, { relations: ['groups', 'groups.parentGroup'] });
for (let group of responseContact.groups) { for (let group of responseContact.groups) {
group.contact = null; group.contact = null;
await getConnection().getRepository(RunnerGroup).save(group); await getConnection().getRepository(RunnerGroup).save(group);

View File

@ -123,7 +123,6 @@ describe('POST /api/contacts working (with group)', () => {
"parentGroup": added_org.id "parentGroup": added_org.id
}, axios_config); }, axios_config);
delete res.data.contact; delete res.data.contact;
delete res.data.parentGroup;
added_team = res.data; added_team = res.data;
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")

View File

@ -74,7 +74,6 @@ describe('Update contact group after adding (should work)', () => {
"parentGroup": added_org.id "parentGroup": added_org.id
}, axios_config); }, axios_config);
delete res.data.contact; delete res.data.contact;
delete res.data.parentGroup;
added_team = res.data; added_team = res.data;
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")
@ -112,6 +111,7 @@ describe('Update contact group after adding (should work)', () => {
"lastname": "last", "lastname": "last",
"groups": added_team.id "groups": added_team.id
}, axios_config); }, axios_config);
console.log(res.data)
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).toEqual({ expect(res.data).toEqual({