forked from DuendeArchive/identity-model-oidc-client-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebStorageStateStore.spec.js
More file actions
168 lines (128 loc) · 4.77 KB
/
Copy pathWebStorageStateStore.spec.js
File metadata and controls
168 lines (128 loc) · 4.77 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
import Log from '../../src/Log';
import WebStorageStateStore from '../../src/WebStorageStateStore';
import InMemoryWebStorage from '../../src/InMemoryWebStorage';
import chai from 'chai';
chai.should();
let assert = chai.assert;
let expect = chai.expect;
describe("WebStorageStateStore", function() {
let prefix;
let subject;
let store;
beforeEach(function() {
prefix = "";
store = new InMemoryWebStorage();
subject = new WebStorageStateStore({ prefix: prefix, store: store });
});
describe("set", function() {
it("should return a promise", function() {
subject.set("key", "value").should.be.instanceof(Promise);
});
it("should store item", function(done) {
subject.set("key", "value").then(() => {
store.getItem("key").should.equal("value");
done();
})
});
it("should use prefix if specified", function(done) {
prefix = "foo.";
subject = new WebStorageStateStore({ prefix: prefix, store: store });
subject.set("key", "value").then(() => {
store.getItem(prefix + "key").should.equal("value");
done();
})
});
});
describe("remove", function() {
it("should return a promise", function() {
subject.remove("key").should.be.instanceof(Promise);
});
it("should remove item", function(done) {
store.setItem("key", "value");
subject.remove("key").then(item => {
expect(store.getItem("key")).to.be.undefined;
done();
});
});
it("should return value if exists", function(done) {
store.setItem("key", "test");
subject.remove("key").then(value => {
value.should.equal('test');
done();
});
});
it("should return undefined if doesn't exist", function(done) {
subject.remove("key").then(value => {
expect(value).to.be.undefined;
done();
});
});
it("should use prefix if specified", function(done) {
prefix = "foo.";
subject = new WebStorageStateStore({ prefix: prefix, store: store });
store.setItem("foo.key", "value");
subject.remove("key").then(item => {
expect(store.getItem("foo.key")).to.be.undefined;
done();
});
});
});
describe("get", function() {
it("should return a promise", function() {
subject.get("key").should.be.instanceof(Promise);
});
it("should return value if exists", function(done) {
store.setItem("key", "test");
subject.get("key").then(value => {
value.should.equal('test');
done();
});
});
it("should return undefined if doesn't exist", function(done) {
subject.get("key").then(value => {
expect(value).to.be.undefined;
done();
});
});
it("should use prefix if specified", function(done) {
prefix = "foo.";
subject = new WebStorageStateStore({ prefix: prefix, store: store });
store.setItem("foo.key", "value");
subject.get("key").then(item => {
item.should.equal("value");
done();
});
});
});
describe("getAllKeys", function() {
it("should return a promise", function() {
subject.getAllKeys().should.be.instanceof(Promise);
});
it("should return keys", function(done) {
store.setItem("key1", "test");
store.setItem("key2", "test");
subject.getAllKeys().then(keys => {
keys.should.deep.equal(["key1", "key2"]);
done();
});
});
it("should return keys without prefix", function(done) {
prefix = "foo.";
subject = new WebStorageStateStore({ prefix: prefix, store: store });
store.setItem("foo.key1", "test");
store.setItem("foo.key2", "test");
subject.getAllKeys().then(keys => {
keys.should.deep.equal(["key1", "key2"]);
done();
});
});
it("should return empty keys when empty", function(done) {
subject.getAllKeys().then(keys => {
keys.should.deep.equal([]);
done();
});
});
});
});