Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hofstede-matheus committed Oct 9, 2023
1 parent 1165668 commit 6e00ddd
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 27 deletions.
74 changes: 55 additions & 19 deletions test/integration/flows.integration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
import { INestApplication } from '@nestjs/common';
import request from 'supertest';
import { generateTestingApp, generateUser, VALID_CLIENT } from '../helpers';
import { generateTestingApp, generateUser } from '../helpers';
import { connectionSource } from '../../ormconfig-test';
import { CreateOrganizationRequest } from '../../src/modules/organizations/presentation/http/dto/CreateOrganization';
import { CreateServiceRequest } from '../../src/modules/services/presentation/http/dto/CreateService';
import { CreateGroupRequest } from '../../src/modules/groups/presentation/http/dto/CreateGroup';
import { ImportClientsRequest } from '../../src/modules/groups/presentation/http/dto/ImportClients';
import { SetUserRoleInOrganizationRequest } from '../../src/modules/users/presentation/http/dto/SetUserRoleInOrganization';
import { CreateQueueRequest } from '../../src/modules/queues/presentation/http/dto/CreateQueue';
import { AttachGroupsToQueueRequest } from '../../src/modules/queues/presentation/http/dto/UpdateQueue';
import { EnterQueueRequest } from '../../src/modules/queues/presentation/http/dto/EnterQueue';
import { CallNextOnQueueRequest } from '../../src/modules/queues/presentation/http/dto/CallNextOnQueue';
import moment from 'moment';
import { EnterServiceRequest } from '../../src/modules/services/presentation/http/dto/EnterService';
import {
attachGroupToQueue,
createGroup,
createOrganization,
createQueue,
Expand All @@ -26,6 +14,8 @@ import {
createDesk,
attachDeskToService,
callNextOnDesk,
updateQueue,
getClientPositionInService,
} from './helpers';

describe('flows', () => {
Expand Down Expand Up @@ -58,14 +48,14 @@ describe('flows', () => {
it('should able to do a complete flow simple', async () => {
/* ------------------COORDINATOR------------------*/

await createOrganization();
await createService();
await createGroup();
await createDesk();
await createQueue();
const organization = await createOrganization();
const service = await createService();
const group = await createGroup();
const desk = await createDesk();
const queue = await createQueue();

await importStudentsToGroup();
await attachGroupToQueue();
await updateQueue();
await attachDeskToService();

/* ------------------ALUNOS------------------*/
Expand All @@ -74,6 +64,23 @@ describe('flows', () => {
await enterService('123456789');
await enterService('1234567890');

const position1 = await getClientPositionInService({
registrationId: '12345678',
serviceId: service.body.id,
});
let position2 = await getClientPositionInService({
registrationId: '123456789',
serviceId: service.body.id,
});
let position3 = await getClientPositionInService({
registrationId: '1234567890',
serviceId: service.body.id,
});

expect(position1.position).toBe(1);
expect(position2.position).toBe(2);
expect(position3.position).toBe(3);

/* ------------------COORDINATOR------------------*/

const getQueueResponse = await getQueue();
Expand All @@ -85,6 +92,18 @@ describe('flows', () => {

await callNextOnDesk();

position2 = await getClientPositionInService({
registrationId: '123456789',
serviceId: service.body.id,
});
position3 = await getClientPositionInService({
registrationId: '1234567890',
serviceId: service.body.id,
});

expect(position2.position).toBe(1);
expect(position3.position).toBe(2);

const getQueueResponse2 = await getQueue();

expect(getQueueResponse2.body.clients.length).toBe(2);
Expand All @@ -93,6 +112,23 @@ describe('flows', () => {
expect(getQueueResponse2.body.lastClientCalled.registrationId).toBe(
'12345678',
);

await callNextOnDesk();

position3 = await getClientPositionInService({
registrationId: '1234567890',
serviceId: service.body.id,
});

expect(position3.position).toBe(1);

const getQueueResponse3 = await getQueue();

expect(getQueueResponse3.body.clients.length).toBe(1);
expect(getQueueResponse3.body.clients[0].registrationId).toBe('1234567890');
expect(getQueueResponse3.body.lastClientCalled.registrationId).toBe(
'123456789',
);
});

// it('should able to do a complete flow calling next 2 times', async () => {
Expand Down
127 changes: 119 additions & 8 deletions test/integration/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { UpdateDeskRequest } from '../../src/modules/desk/presentation/http/dto/
import { CreateClientRequest } from '../../src/modules/clients/presentation/http/dto/CreateClient';
import { UserEntityTypes } from '../../src/modules/users/domain/entities/User.entity';
import { UpdateClientRequest } from '../../src/modules/clients/presentation/http/dto/UpdateClient';
import moment from 'moment';
import { UpdateQueueRequest } from '../../src/modules/queues/presentation/http/dto/UpdateQueue';

let app = null;
let USER = null;
Expand Down Expand Up @@ -126,23 +128,81 @@ export async function updateClient(
return client.body;
}

export async function createService() {
export async function createService(
{
name,
subscriptionToken,
guestEnrollment,
opensAt,
closesAt,
organizationId,
} = {
name: 'BSI',
subscriptionToken: 'BSI',
guestEnrollment: true,
opensAt: moment().toString(),
closesAt: moment().add(1, 'day').add(1, 'hour').toString(),
organizationId: organization.body.id,
} as {
name?: string;
subscriptionToken?: string;
guestEnrollment?: boolean;
opensAt?: string;
closesAt?: string;
organizationId?: string;
},
) {
service = await request(app.getHttpServer())
.post('/v1/services')
.post('/v1/admin/services')
.set('Authorization', USER.token)
.send({
name: 'Matrícula BSI',
subscriptionToken: 'BSI-2023-2',
guestEnrollment: true,
opensAt: opensAt.toISOString(),
closesAt: closesAt.toISOString(),
organizationId: organization.body.id,
name,
subscriptionToken,
guestEnrollment,
opensAt,
closesAt,
organizationId,
} as CreateServiceRequest)
.set('Accept', 'application/json')
.expect(201);
return service;
}

export async function updateQueue(
{ name, description, code, priority, groups, serviceId, organizationId } = {
name: queue.body.name,
description: queue.body.description,
code: queue.body.code,
priority: queue.body.priority,
groups: [group.body.id],
serviceId: service.body.id,
organizationId: organization.body.id,
} as {
name?: string;
description?: string;
code?: string;
priority?: number;
groups?: string[];
serviceId?: string;
organizationId?: string;
},
) {
queue = await request(app.getHttpServer())
.patch(`/v1/queues/${queue.body.id}/organizations/${organizationId}`)
.set('Authorization', USER.token)
.send({
name,
description,
code,
priority,
groups,
serviceId,
} as UpdateQueueRequest)
.set('Accept', 'application/json')
.expect(200);
return queue.body;
}

export async function createGroup() {
group = await request(app.getHttpServer())
.post('/v1/groups')
Expand Down Expand Up @@ -257,3 +317,54 @@ export async function callNextOnDesk() {

return callNextOnDeskResponse;
}
// /v1/services/{serviceId}/position/{registrationId}": {
// "get": {
// "operationId": "ServiceController_getClientPositionInService",
// "parameters": [
// {
// "name": "serviceId",
// "required": true,
// "in": "path",
// "schema": {
// "type": "string"
// }
// },
// {
// "name": "registrationId",
// "required": true,
// "in": "path",
// "schema": {
// "type": "string"
// }
// }
// ],
// "responses": {
// "default": {
// "description": "",
// "content": {
// "application/json": {
// "schema": {
// "type": "number"
// }
// }
// }
// }
// }
// }
// },
export async function getClientPositionInService(
{ serviceId, registrationId } = {
serviceId: service.body.id,
registrationId: client.body.registrationId,
} as {
serviceId?: string;
registrationId?: string;
},
) {
const getClientPositionInServiceResponse = await request(app.getHttpServer())
.get(`/v1/services/${serviceId}/position/${registrationId}`)
.set('Accept', 'application/json')
.expect(200);

return getClientPositionInServiceResponse.body;
}

0 comments on commit 6e00ddd

Please sign in to comment.