Skip to content

Commit 4a55b71

Browse files
committed
Base tests for solid
1 parent 555b565 commit 4a55b71

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

test/unit/solid-suite.js

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
if (typeof define !== 'function') {
2+
var define = require('amdefine')(module);
3+
}
4+
define(['util', 'require', './build/eventhandling', './build/solid',
5+
'./build/config', './build/util', 'test/behavior/backend',
6+
'test/helpers/mocks'],
7+
function (util, require, EventHandling, Solid, config, buildUtil,
8+
backend, mocks) {
9+
10+
var suites = [];
11+
12+
function setup (env, test) {
13+
global.localStorage = {
14+
setItem: function() {},
15+
removeItem: function() {}
16+
};
17+
18+
class RemoteStorage {
19+
setBackend (b) { this.backend = b; }
20+
}
21+
buildUtil.applyMixins(RemoteStorage, [EventHandling]);
22+
global.RemoteStorage = RemoteStorage;
23+
24+
global.Authorize = require('./build/authorize');
25+
26+
test.done();
27+
}
28+
29+
function beforeEach(env, test) {
30+
env.rs = new RemoteStorage();
31+
env.rs.addEvents(['error', 'wire-busy', 'wire-done', 'network-offline', 'network-online']);
32+
var oldLocalStorageAvailable = util.localStorageAvailable;
33+
util.localStorageAvailable = function() { return true; };
34+
env.client = new Solid(env.rs);
35+
env.connectedClient = new Solid(env.rs);
36+
util.localStorageAvailable = oldLocalStorageAvailable;
37+
38+
/*
39+
{
40+
"href": "https://solidcommunity.net",
41+
"userAddress": "https://yasharpm.solidcommunity.net/profile/ca"
42+
"properties": {
43+
"sessionProperties": {
44+
"clientId": "f3746db1ad9c6e83ec2c3ef76fd7dba5",
45+
"clientSecret": "43ef2f966cbd1d6a974a9af590847daf",
46+
"idTokenSignedResponseAlg": "RS256",
47+
"sessionId": "any",
48+
"codeVerifier": "3099e5e6e8d14a1c9a0ad328a2421d5a6f8f30f7c7b648c48326dd987df5ccf4c285700f206c4f4d8d24aacf664e1823",
49+
"issuer": "https://solidcommunity.net",
50+
"redirectUrl": "https://8080-pondersource-devstock-73mdx98iw45.ws-eu115.gitpod.io/",
51+
"dpop": "true"
52+
},
53+
"podURL": "https://yasharpm.solidcommunity.net/"
54+
}
55+
}
56+
*/
57+
58+
env.baseURI = 'https://example.com/storage/test';
59+
env.connectedClient.configure({
60+
userAddress: 'soliduser',
61+
href: env.baseURI,
62+
properties: {
63+
podURL: 'https://example.com/storage/test'
64+
}
65+
});
66+
67+
mocks.defineMocks(env);
68+
69+
env.busy = new test.Stub(function(){});
70+
env.done = new test.Stub(function(){});
71+
env.networkOffline = new test.Stub(function(){});
72+
env.networkOnline = new test.Stub(function(){});
73+
env.rs.on('wire-busy', env.busy);
74+
env.rs.on('wire-done', env.done);
75+
env.rs.on('network-offline', env.networkOffline);
76+
env.rs.on('network-online', env.networkOnline);
77+
78+
test.done();
79+
}
80+
81+
function afterEach(env, test) {
82+
mocks.undefineMocks(env);
83+
delete env.client;
84+
test.done();
85+
}
86+
87+
suites.push({
88+
name: "Solid",
89+
desc: "backend behavior",
90+
setup: setup,
91+
beforeEach: beforeEach,
92+
afterEach: afterEach,
93+
tests: backend.behavior
94+
});
95+
96+
var tests = [
97+
{
98+
desc: "#configure sets 'connected' to true, once sessionProperties is given",
99+
run: function (env, test) {
100+
env.client.configure({
101+
sessionProperties: { }
102+
});
103+
test.assert(env.client.connected, true);
104+
}
105+
},
106+
107+
{
108+
desc: "#configure sets userAddress when given",
109+
run: function (env, test) {
110+
env.client.configure({
111+
userAddress: '[email protected]'
112+
});
113+
test.assert(env.client.userAddress, '[email protected]');
114+
}
115+
},
116+
117+
118+
];
119+
120+
suites.push({
121+
name: "Solid",
122+
desc: "Solid back-end",
123+
setup: setup,
124+
beforeEach: beforeEach,
125+
afterEach: afterEach,
126+
tests: tests
127+
});
128+
129+
130+
return suites;
131+
});
132+

0 commit comments

Comments
 (0)