-
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
|
||
const { test } = require('ava'); | ||
const store = require('./../../../test/fixtures/store'); | ||
const supertest = require('supertest'); | ||
const getApp = require('../../app'); | ||
const User = require('../../user'); | ||
|
||
const { EventEmitter } = require('events'); | ||
const eventBus = new EventEmitter(); | ||
|
||
const currentUser = new User({ email: '[email protected]' }); | ||
|
||
function getSetup() { | ||
const base = `/random${Math.round(Math.random() * 1000)}`; | ||
const stores = store.createStores(); | ||
const app = getApp({ | ||
baseUriPath: base, | ||
stores, | ||
eventBus, | ||
preHook: a => { | ||
a.use((req, res, next) => { | ||
req.user = currentUser; | ||
next(); | ||
}); | ||
}, | ||
}); | ||
|
||
return { | ||
base, | ||
strategyStore: stores.strategyStore, | ||
request: supertest(app), | ||
}; | ||
} | ||
|
||
test('should return current user', t => { | ||
t.plan(1); | ||
const { request, base } = getSetup(); | ||
|
||
return request | ||
.get(`${base}/api/admin/user`) | ||
.expect(200) | ||
.expect('Content-Type', /json/) | ||
.expect(res => { | ||
t.true(res.body.email === currentUser.email); | ||
}); | ||
}); | ||
|
||
test('should logout and redirect', t => { | ||
t.plan(0); | ||
const { request, base } = getSetup(); | ||
|
||
return request | ||
.get(`${base}/api/admin/user/logout`) | ||
.expect(302) | ||
.expect('Location', '/'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters