add snapshot tests for invites endpoint

This commit is contained in:
Riku Rouvila
2017-09-03 14:59:09 +01:00
parent 07b695612f
commit 2096662b70
6 changed files with 2182 additions and 4 deletions

View File

@@ -0,0 +1,60 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`invite endpoint invites user to github org 1`] = `
Object {
"body": Object {
"role": "member",
},
"headers": Object {
"authorization": "token ",
},
"params": Object {
"login": "rikukissa",
},
"query": Object {},
"url": "https://api.github.com/orgs/koodiklinikka/memberships/rikukissa",
}
`;
exports[`invite endpoint responds with 200 status 1`] = `
Object {
"body": Object {},
"headers": Object {
"access-control-allow-credentials": "true",
"connection": "close",
"content-length": "0",
"vary": "Origin",
"x-powered-by": "Express",
},
"status": 200,
}
`;
exports[`invite endpoint send an invite request to slack's api 1`] = `
Object {
"body": Object {
"channels": "",
"email": "test@example.com",
"set_active": "true",
"token": "",
},
"headers": Object {},
"params": Object {},
"query": Object {},
"url": "https://koodiklinikka.slack.com/api/users.admin.invite",
}
`;
exports[`invite endpoint tries searching for the user from github API 1`] = `
Object {
"body": Object {},
"headers": Object {
"authorization": "token ",
},
"params": Object {},
"query": Object {
"q": "test@example.com",
},
"url": "https://api.github.com/search/users",
}
`;

67
tests/invite.test.js Normal file
View File

@@ -0,0 +1,67 @@
const test = require('supertest')
const app = require('../index')
const { omit } = require('lodash')
const request = require('superagent')
const mocker = require('superagent-mocker')
const mock = mocker(request)
function resolveAllPromises() {
return new Promise((resolve) => setTimeout(resolve))
}
describe('invite endpoint', () => {
let slackInviteSpy
let githubSearchSpy
let githubOrgInviteSpy
let response
beforeEach(async () => {
slackInviteSpy = jest.fn((req) => ({
body: {ok: true}
}));
githubSearchSpy = jest.fn((req) => ({
body: {items: [{login: 'rikukissa'}]}
}));
githubOrgInviteSpy = jest.fn((req) => ({
body: {user: {login: 'rikukissa'}}
}));
mock.post('https://koodiklinikka.slack.com/api/users.admin.invite', slackInviteSpy);
mock.get('https://api.github.com/search/users', githubSearchSpy);
mock.put('https://api.github.com/orgs/koodiklinikka/memberships/:login', githubOrgInviteSpy);
response = await test(app)
.post('/invites')
.send({email: 'test@example.com'})
.expect(200)
await resolveAllPromises()
})
afterEach(() => mock.clearRoutes())
it("responds with 200 status", () => {
expect({
headers: omit(response.headers, 'date'),
body: response.body,
status: response.status
}).toMatchSnapshot()
})
it("send an invite request to slack's api", () => {
expect(slackInviteSpy).toHaveBeenCalled()
expect(slackInviteSpy.mock.calls[0][0]).toMatchSnapshot();
})
it('tries searching for the user from github API', () => {
expect(githubSearchSpy).toHaveBeenCalled()
expect(githubSearchSpy.mock.calls[0][0]).toMatchSnapshot();
})
it('invites user to github org', () => {
expect(githubOrgInviteSpy).toHaveBeenCalled()
expect(githubOrgInviteSpy.mock.calls[0][0]).toMatchSnapshot();
})
})