Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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('Update 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/234567';

before(async () => {
await pactSetUp.provider.setup();
const interaction = {
state: 'Professional User exists for modification of user access types with identifier 234567',
uponReceiving: 'a request to update the roles and access types 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 = '234567';
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');
}
2 changes: 1 addition & 1 deletion yarn-audit-known-issues

Large diffs are not rendered by default.