Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ga 97 test pact changes #1251

Open
wants to merge 9 commits into
base: development/GA/OGD-73-Invite-User-Flow
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { expect } from 'chai';
import { InviteUserResponse } from '../pactFixtures';
import { inviteUser } from '../pactUtil';
import { PactTestSetup } from '../settings/provider.mock';

import { Matchers } from '@pact-foundation/pact';
const { somethingLike } = Matchers;
const pactSetUp = new PactTestSetup({ provider: 'referenceData_organisationalExternalUsers', port: 8000 });

describe('RD Professional API', () => {
describe('Invite User', () => {
const mockRequest = {
'email': '[email protected]',
'firstName': 'Joe',
'lastName': 'Bloggs',
'roles': ['admin'],
'resendInvite': true,
'userAccessTypes': [
{
'jurisdictionId': 'jurisdictionId1',
'organisationProfileId': 'organisationProfileId1',
'accessTypeId': 'accessTypeId1',
'enabled': true
}
]
};

const mockResponse = {
userIdentifier: somethingLike('urlIdentifier')
};

const requestPath = '/refdata/external/v1/organisations/users/';

before(async () => {
await pactSetUp.provider.setup();
const interaction = {
state: 'Organisation exists that can invite new users with AccessTypes',
uponReceiving: 'A request to invite a new user',
withRequest: {
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=utf-8',
'Authorization': 'Bearer some-access-token',
'ServiceAuthorization': 'serviceAuthToken'
},
path: requestPath,
body: mockRequest
},
willRespondWith: {
headers: {
'Content-Type': 'application/json'
},
status: 201,
body: mockResponse
}
};
// @ts-ignore
pactSetUp.provider.addInteraction(interaction);
});

it('returns the correct response', async () => {
const taskUrl: string = `${pactSetUp.provider.mockService.baseUrl}/refdata/external/v1/organisations/users/`;
const resp = inviteUser(taskUrl, mockRequest as any);
resp.then((response) => {
const responseDto: InviteUserResponse = <InviteUserResponse>response.data;
assertResponse(responseDto);
}).then(() => {
pactSetUp.provider.verify();
pactSetUp.provider.finalize();
}).finally(() => {
pactSetUp.provider.verify();
pactSetUp.provider.finalize();
});
});
});
});

function assertResponse(dto: InviteUserResponse): void {
expect(dto.userIdentifier).to.be.equal('urlIdentifier');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { expect } from 'chai';
import { SuspendUserReponseDto } from '../pactFixtures';
import { suspendUser } from '../pactUtil';
import { PactTestSetup } from '../settings/provider.mock';

import { Matchers } from '@pact-foundation/pact';
const { somethingLike } = Matchers;
const pactSetUp = new PactTestSetup({ provider: 'referenceData_professionalExternalUsers', port: 8000 });

describe('RD Professional API', () => {
describe('Suspend A User With Access Types', async () => {
const mockRequest = {
'email': '[email protected]',
'firstName': 'Joe',
'lastName': 'Bloggs',
'idamStatus': 'active',
'rolesAdd': [
{
'name': 'superuser'
}
],
'userAccessTypes': [
{
'jurisdictionId': 'jurisdictionId1',
'organisationProfileId': 'organisationProfileId1',
'accessTypeId': 'accessTypeId1',
'enabled': true
}
]
};

const mockResponse = {
'roleAdditionResponse': {
'idamMessage': somethingLike('Role successfully Updated'),
'idamStatusCode': somethingLike('200')
}
};

const requestPath = '/refdata/external/v1/organisations/users/123456';

before(async () => {
await pactSetUp.provider.setup();
const interaction = {
state: 'Professional User exists for modification of user access types with identifier 123456',
uponReceiving: 'a request to update the roles of that user',
withRequest: {
method: 'PUT',
headers: {
'Content-Type': 'application/json;charset=utf-8',
'Authorization': 'Bearer some-access-token',
'ServiceAuthorization': 'serviceAuthToken'
},
path: requestPath,
body: mockRequest
},
willRespondWith: {
headers: {
'Content-Type': 'application/json'
},
status: 200,
body: mockResponse
}
};
// @ts-ignore
pactSetUp.provider.addInteraction(interaction);
});

it('returns the correct response', async () => {
// call the pactUtil's method which Calls The Downstream API directly without going through the Service Class.
const userId = '123456';
const taskUrl: string = `${pactSetUp.provider.mockService.baseUrl}/refdata/external/v1/organisations/users/` + userId;

const resp = suspendUser(taskUrl, mockRequest as any);

resp.then((response) => {
const responseDto: SuspendUserReponseDto = <SuspendUserReponseDto>response.data;
assertResponse(responseDto);
}).then(() => {
pactSetUp.provider.verify();
pactSetUp.provider.finalize();
}).finally(() => {
pactSetUp.provider.verify();
pactSetUp.provider.finalize();
});
});
});
});

function assertResponse(dto: SuspendUserReponseDto): void {
expect(dto.roleAdditionResponse.idamMessage).to.equal('Role successfully Updated');
expect(dto.roleAdditionResponse.idamStatusCode).to.equal('200');
}