Skip to content

Commit

Permalink
Merge pull request #109 from cabinetoffice/NTRNL-545-update-collabora…
Browse files Browse the repository at this point in the history
…tor-endpoint-to-match-revised-endpoint-structure

update collaborator endpoint to follow create/collaborator
  • Loading branch information
DanielMurray97 authored Aug 21, 2024
2 parents acda99c + e9e95e6 commit 8e41448
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/routes/github/collaborator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { get, getById, post, postById, removeById } from '../../controller/githu

const CollaboratorRouter = Router();

CollaboratorRouter.get(config.GITHUB_URL + config.COLLABORATOR_URL, authentication, get);
CollaboratorRouter.get(config.GITHUB_URL + config.UPDATE + config.COLLABORATOR_URL + config.PARAM_ID, authentication, getById);
CollaboratorRouter.get(config.GITHUB_URL + config.CREATE + config.COLLABORATOR_URL, authentication, get);
CollaboratorRouter.post(config.GITHUB_URL + config.CREATE + config.COLLABORATOR_URL, authentication, ...Collaborator, checkValidations, post);

CollaboratorRouter.get(config.GITHUB_URL + config.REMOVE + config.COLLABORATOR_URL + config.PARAM_ID, authentication, removeById);

CollaboratorRouter.post(config.GITHUB_URL + config.COLLABORATOR_URL, authentication, ...Collaborator, checkValidations, post);
CollaboratorRouter.get(config.GITHUB_URL + config.UPDATE + config.COLLABORATOR_URL + config.PARAM_ID, authentication, getById);
CollaboratorRouter.post(config.GITHUB_URL + config.UPDATE + config.COLLABORATOR_URL + config.PARAM_ID, authentication, ...Collaborator, checkValidations, postById);

export default CollaboratorRouter;
2 changes: 1 addition & 1 deletion src/views/github-home.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h2 class="govuk-heading-m">General requests</h2>
<a class="govuk-link" href="/github/create/repo">Add a new repository</a>
</li>
<li>
<a class="govuk-link" href="/github/collaborator">Add a new collaborator to a repository</a>
<a class="govuk-link" href="/github/create/collaborator">Add a new collaborator to a repository</a>
</li>
</ul>
<h2 class="govuk-heading-m">Additional requests</h2>
Expand Down
13 changes: 8 additions & 5 deletions test/integration/routes/github/collaborator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,26 @@ const mockedAuth = authentication as jest.Mock<typeof authentication>;
mockedAuth.mockImplementation((_req: Request, _res: Response, next: NextFunction) => next());

describe('Collaborator endpoint integration tests', () => {

const collaboratorEndpoint = config.GITHUB_URL + config.CREATE + config.COLLABORATOR_URL;

beforeEach(() => {
jest.clearAllMocks();
});

describe('GET tests', () => {
test('renders the collaborator page', async () => {
const res = await request(app).get(config.GITHUB_URL + config.COLLABORATOR_URL);
const res = await request(app).get(collaboratorEndpoint);

expect(res.status).toEqual(200);
expect(res.text).toContain(MOCK_GET_COLLABORATOR_RESPONSE);
expect(mockedLogger).toHaveBeenCalledTimes(1);
expect(mockedAuth).toHaveBeenCalledTimes(1);
});
});
describe('Add collaborator POST tests', () => {
describe('collaborator POST tests', () => {
test('Should redirect to github-home page after POST request', async () => {
const res = await request(app).post(config.GITHUB_URL + config.COLLABORATOR_URL).send(MOCK_POST_COLLABORATOR);
const res = await request(app).post(collaboratorEndpoint).send(MOCK_POST_COLLABORATOR);

expect(res.status).toEqual(302);
expect(res.text).toContain(MOCK_GITHUB_HOME_REDIRECT_MESSAGE);
Expand All @@ -51,7 +54,7 @@ describe('Collaborator endpoint integration tests', () => {
});

test('Should render the same page with error messages after POST request', async () => {
const res = await request(app).post(config.GITHUB_URL + config.COLLABORATOR_URL).send({
const res = await request(app).post(collaboratorEndpoint).send({
first_name: '',
last_name: '',
github_handle: '',
Expand All @@ -71,7 +74,7 @@ describe('Collaborator endpoint integration tests', () => {
});

test('Should log the collaborator details on POST request.', async () => {
const res = await request(app).post(config.GITHUB_URL + config.COLLABORATOR_URL).send(MOCK_POST_COLLABORATOR);
const res = await request(app).post(collaboratorEndpoint).send(MOCK_POST_COLLABORATOR);

const mockLog = log.info as jest.Mock;

Expand Down

0 comments on commit 8e41448

Please sign in to comment.