This repository has been archived by the owner on Sep 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
auth.logout.js
59 lines (55 loc) · 1.54 KB
/
auth.logout.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* eslint-disable no-undefined */
import Fetchr from "fetchr";
import { test } from "eater/runner";
import assert from "power-assert";
import { ACCESS_TOKEN_AUDIENCE_NAME } from "server/services/AccessToken";
import { login, logout } from "shared/redux/modules/auth";
import { createWithSignedStore } from "./lib/storeUtils";
/**
* mock accessToken service
*/
Fetchr.registerService({
name: "accessToken",
create(req, resource, params, body, config, cb) {
cb(null, null);
},
delete(req, resource, params, config, cb) {
cb(null, null);
}
});
test("auth: logout success", done => {
const logoutAction = logout();
createWithSignedStore("scott", ACCESS_TOKEN_AUDIENCE_NAME, {}).then(store => {
store.dispatch(logoutAction).then(() => {
assert.deepEqual(store.getState().app.auth, {
login: false,
username: undefined
});
done();
});
});
});
test("auth: logout success when not logged in", done => {
const loginAction = login("foobar", "tiger");
const logoutAction = logout();
createWithSignedStore("foobar", ACCESS_TOKEN_AUDIENCE_NAME, {}).then(
store => {
store
.dispatch(loginAction)
.then(() => {
assert.deepEqual(store.getState().app.auth, {
login: true,
username: "foobar"
});
return store.dispatch(logoutAction);
})
.then(() => {
assert.deepEqual(store.getState().app.auth, {
login: false,
username: undefined
});
done();
});
}
);
});