mirror of
https://github.com/koodiklinikka/koodiklinikka.fi-api.git
synced 2026-03-12 19:03:24 +00:00
add snapshot tests for invites endpoint
This commit is contained in:
6
index.js
6
index.js
@@ -31,4 +31,8 @@ app.use(function(err, req, res, next) {
|
||||
res.status(500).send('Internal server error');
|
||||
});
|
||||
|
||||
app.listen(process.env.PORT || 9000);
|
||||
if(!module.parent) {
|
||||
app.listen(process.env.PORT || 9000);
|
||||
}
|
||||
|
||||
module.exports = app;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
var _ = require('lodash');
|
||||
var config = {};
|
||||
const template = require('../config.template.json');
|
||||
|
||||
try {
|
||||
config = require('../config.json');
|
||||
@@ -25,4 +26,4 @@ var envVars = _.reduce(process.env, function(memo, value, key) {
|
||||
return _.set(memo, toPath(key), value);
|
||||
}, {});
|
||||
|
||||
module.exports = _.merge({}, config.all, config[env], envVars);
|
||||
module.exports = _.merge({}, template.development, config.all, config[env], envVars);
|
||||
|
||||
2041
package-lock.json
generated
2041
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -4,7 +4,7 @@
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"test": "jest",
|
||||
"start": "node index.js",
|
||||
"snyk-protect": "snyk protect",
|
||||
"prepublish": "npm run snyk-protect"
|
||||
@@ -38,5 +38,10 @@
|
||||
"validator": "^3.27.0",
|
||||
"snyk": "^1.38.1"
|
||||
},
|
||||
"snyk": true
|
||||
"snyk": true,
|
||||
"devDependencies": {
|
||||
"jest": "^20.0.4",
|
||||
"superagent-mocker": "maxkoryukov/superagent-mocker#feature/mock-field-method",
|
||||
"supertest": "^3.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
60
tests/__snapshots__/invite.test.js.snap
Normal file
60
tests/__snapshots__/invite.test.js.snap
Normal 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
67
tests/invite.test.js
Normal 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();
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user