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.login.js
72 lines (64 loc) · 1.91 KB
/
auth.login.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
60
61
62
63
64
65
66
67
68
69
70
71
72
/* 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 } from "shared/redux/modules/auth";
import { createStore, createWithSignedStore } from "./lib/storeUtils";
/**
* mock accessToken service
*/
Fetchr.registerService({
name: "accessToken",
create(req, resource, params, body, config, cb) {
if (params && params.username === "s") {
return void cb(new Error("username is short"));
}
cb(null, null);
}
});
test("auth: login success username scott", () => {
const loginAction = login("scott", "tiger");
createWithSignedStore("scott", ACCESS_TOKEN_AUDIENCE_NAME, {}).then(store => {
store.dispatch(loginAction).then(() => {
assert.deepEqual(store.getState().app.auth, {
login: true,
username: "scott"
});
});
});
});
test("auth: login success username foobar", () => {
const loginAction = login("foobar", "tiger");
createWithSignedStore("foobar", ACCESS_TOKEN_AUDIENCE_NAME, {}).then(
store => {
store.dispatch(loginAction).then(() => {
assert.deepEqual(store.getState().app.auth, {
login: true,
username: "foobar"
});
});
}
);
});
test("auth: login failure invalid audience name", (_, fail) => {
const loginAction = login("scott", "tiger");
createWithSignedStore("scott", "no-such-audience", {})
.then(store => store.dispatch(loginAction))
.then(fail, e => {
assert(e.message === "invalid token");
});
});
test("auth: login failure username is short", (_, fail) => {
const loginAction = login("s", "tiger");
const store = createStore({
cookie: {}
});
store.dispatch(loginAction).then(fail, e => {
assert.deepEqual(store.getState().app.auth, {
login: false,
username: null
});
assert(e);
});
});