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 22 23 24 #1260

Open
wants to merge 19 commits into
base: development/GA/OGD-73-Invite-User-Flow
Choose a base branch
from
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
27 changes: 27 additions & 0 deletions api/test/pact/pact-tests/pactFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,33 @@ export interface Organisation {
superUser: SuperUser;
}

export interface OrganisationWithUsers {
organisationIdentifier: string,
organisationStatus: string,
organisationProfileIds: string[],
users: [
{
userIdentifier: string,
firstName: string,
lastName: string,
email: string,
idamStatus: string,
roles: string[];
idamStatusCode: string,
idamMessage: string,
lastUpdated: string,
userAccessTypes: UserAccessType[]
}
]
}

export interface UserAccessType {
jurisdictionId: string,
organisationProfileId: string,
accessTypeId: string,
enabled: boolean
}

export interface SuspendUserReponseDto {
roleAdditionResponse?: RoleResponse;
roleDeletionResponse?: RoleDeletionResponse[];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { expect } from 'chai';
import { OrganisationWithUsers } from '../pactFixtures';
import { getOrganisationDetails } 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('Get all users for organistion', async () => {
before(async () => {
await pactSetUp.provider.setup();
const interaction = {
state: 'Professional User exists for get Organisation with user access types with identifier HM2OHHS',
uponReceiving: 'A request for from a logged in user of that organisation',
withRequest: {
method: 'GET',
path: '/refdata/external/v1/organisations/users',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer some-access-token',
'ServiceAuthorization': 'serviceAuthToken'
}
},
willRespondWith: {
status: 200,
headers: {
'Content-type': 'application/json'
},
body:
organisationResponse

}
};
// @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 = getOrganisationDetails(taskUrl);

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

function assertResponse(dto: OrganisationWithUsers): void {
// eslint-disable-next-line no-unused-expressions
expect(dto).to.be.not.null;
expect(dto.organisationIdentifier).to.equal('K100');
expect(dto.organisationStatus).to.equal('ACTIVE');
}

const organisationResponse =
{
organisationIdentifier: somethingLike('K100'),
organisationStatus: somethingLike('ACTIVE'),
organisationProfileIds: [
somethingLike('SOLICITOR_PROFILE')
],
users: somethingLike([{
userIdentifier: somethingLike(''),
firstName: somethingLike('firstName1'),
lastName: somethingLike('lastName1'),
email: somethingLike('[email protected]'),
idamStatus: somethingLike('ACTIVE'),
lastUpdated: somethingLike(''),
roles: null,
idamStatusCode: somethingLike('200'),
idamMessage: somethingLike('11 OK'),
userAccessTypes: [
{
jurisdictionId: somethingLike('12345'),
organisationProfileId: somethingLike('12345'),
accessTypeId: somethingLike('1234'),
enabled: somethingLike('true')
}
]
}])
};
});
});
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.