1 | process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
|
2 | const {token, domain} = require('./config.js');
|
3 | import oada from "../src/index";
|
4 | import chai from "chai";
|
5 | import { getConnections } from './utils'
|
6 | var chaiAsPromised = require("chai-as-promised");
|
7 | chai.use(chaiAsPromised);
|
8 | var expect = chai.expect;
|
9 |
|
10 | let connections = new Array(4);
|
11 | let contentType = "application/vnd.oada.yield.1+json";
|
12 | let connectTime = 30 * 1000;
|
13 |
|
14 | describe("~~~~~~ CONNECTIONS~~~~~~~", function() {
|
15 | this.timeout(connectTime);
|
16 |
|
17 | it("Should connect with metadata. Browser popup must be used to login within 30s.", async function() {
|
18 | this.timeout(connectTime);
|
19 | var result = await oada.connect({
|
20 | domain,
|
21 | options: {
|
22 | redirect: "http://localhost:8000/oauth2/redirect.html",
|
23 | metadata:
|
24 | "eyJqa3UiOiJodHRwczovL2lkZW50aXR5Lm9hZGEtZGV2LmNvbS9jZXJ0cyIsImtpZCI6ImtqY1NjamMzMmR3SlhYTEpEczNyMTI0c2ExIiwidHlwIjoiSldUIiwiYWxnIjoiUlMyNTYifQ.eyJyZWRpcmVjdF91cmlzIjpbImh0dHA6Ly92aXAzLmVjbi5wdXJkdWUuZWR1OjgwMDAvb2F1dGgyL3JlZGlyZWN0Lmh0bWwiLCJodHRwOi8vbG9jYWxob3N0OjgwMDAvb2F1dGgyL3JlZGlyZWN0Lmh0bWwiXSwidG9rZW5fZW5kcG9pbnRfYXV0aF9tZXRob2QiOiJ1cm46aWV0ZjpwYXJhbXM6b2F1dGg6Y2xpZW50LWFzc2VydGlvbi10eXBlOmp3dC1iZWFyZXIiLCJncmFudF90eXBlcyI6WyJpbXBsaWNpdCJdLCJyZXNwb25zZV90eXBlcyI6WyJ0b2tlbiIsImlkX3Rva2VuIiwiaWRfdG9rZW4gdG9rZW4iXSwiY2xpZW50X25hbWUiOiJPcGVuQVRLIiwiY2xpZW50X3VyaSI6Imh0dHBzOi8vdmlwMy5lY24ucHVyZHVlLmVkdSIsImNvbnRhY3RzIjpbIlNhbSBOb2VsIDxzYW5vZWxAcHVyZHVlLmVkdT4iXSwic29mdHdhcmVfaWQiOiIxZjc4NDc3Zi0zNTQxLTQxM2ItOTdiNi04NjQ0YjRhZjViYjgiLCJyZWdpc3RyYXRpb25fcHJvdmlkZXIiOiJodHRwczovL2lkZW50aXR5Lm9hZGEtZGV2LmNvbSIsImlhdCI6MTUxMjAwNjc2MX0.AJSjNlWX8UKfVh-h1ebCe0MEGqKzArNJ6x0nmta0oFMcWMyR6Cn2saR-oHvU8WrtUMEr-w020mAjvhfYav4EdT3GOGtaFgnbVkIs73iIMtr8Z-Y6mDEzqRzNzVRMLghj7CyWRCNJEk0jwWjOuC8FH4UsfHmtw3ouMFomjwsNLY0",
|
25 | scope: "oada.yield:all"
|
26 | },
|
27 | cache: false
|
28 | })
|
29 | expect(result).to.have.keys([
|
30 | "token",
|
31 | "cache",
|
32 | "websocket",
|
33 | "disconnect",
|
34 | "reconnect",
|
35 | "get",
|
36 | "put",
|
37 | "post",
|
38 | "delete",
|
39 | "resetCache"
|
40 | ]);
|
41 | expect(result.cache).to.equal(false);
|
42 | expect(result.websocket).to.be.a("object");
|
43 | expect(result.get).to.be.a("function");
|
44 | expect(result.put).to.be.a("function");
|
45 | expect(result.post).to.be.a("function");
|
46 | expect(result.resetCache).to.be.a("function");
|
47 | expect(result.disconnect).to.be.a("function");
|
48 | });
|
49 |
|
50 | it("Should make a connection with websocket and cache", async function() {
|
51 | this.timeout(connectTime);
|
52 | var result = await oada.connect({
|
53 | domain,
|
54 | token,
|
55 | })
|
56 | connections[0] = result;
|
57 | expect(result).to.have.keys([
|
58 | "token",
|
59 | "disconnect",
|
60 | "reconnect",
|
61 | "get",
|
62 | "put",
|
63 | "post",
|
64 | "delete",
|
65 | "resetCache",
|
66 | "cache",
|
67 | "websocket"
|
68 | ]);
|
69 | expect(result.cache).to.be.a("object");
|
70 | expect(result.websocket).to.be.a("object");
|
71 | expect(result.get).to.be.a("function");
|
72 | expect(result.put).to.be.a("function");
|
73 | expect(result.post).to.be.a("function");
|
74 | expect(result.resetCache).to.be.a("function");
|
75 | expect(result.disconnect).to.be.a("function");
|
76 | });
|
77 |
|
78 | it("Should make a connection with websocket off, cache on", async function() {
|
79 | this.timeout(connectTime);
|
80 | var result = await oada.connect({
|
81 | domain,
|
82 | token,
|
83 | websocket: false
|
84 | })
|
85 | connections[1] = result;
|
86 | expect(result).to.have.keys([
|
87 | "token",
|
88 | "disconnect",
|
89 | "reconnect",
|
90 | "get",
|
91 | "put",
|
92 | "post",
|
93 | "delete",
|
94 | "resetCache",
|
95 | "cache",
|
96 | "websocket"
|
97 | ]);
|
98 |
|
99 | expect(result.cache).to.be.a("object");
|
100 | expect(result.websocket).to.equal(false);
|
101 | expect(result.get).to.be.a("function");
|
102 | expect(result.put).to.be.a("function");
|
103 | expect(result.post).to.be.a("function");
|
104 | expect(result.resetCache).to.be.a("function");
|
105 | expect(result.disconnect).to.be.a("function");
|
106 | });
|
107 |
|
108 | it("Should make a connection with websocket on, cache off", async function() {
|
109 | this.timeout(connectTime);
|
110 | var result = await oada.connect({
|
111 | domain,
|
112 | token: "def",
|
113 | cache: false
|
114 | })
|
115 | connections[2] = result;
|
116 | expect(result).to.have.keys([
|
117 | "token",
|
118 | "disconnect",
|
119 | "get",
|
120 | "put",
|
121 | "post",
|
122 | "reconnect",
|
123 | "delete",
|
124 | "resetCache",
|
125 | "cache",
|
126 | "websocket"
|
127 | ]);
|
128 | expect(result.cache).to.equal(false);
|
129 | expect(result.websocket).to.be.a("object");
|
130 | expect(result.get).to.be.a("function");
|
131 | expect(result.put).to.be.a("function");
|
132 | expect(result.post).to.be.a("function");
|
133 | expect(result.resetCache).to.be.a("function");
|
134 | expect(result.disconnect).to.be.a("function");
|
135 | });
|
136 |
|
137 | it("Should make a connection with websocket off, cache off", async function() {
|
138 | this.timeout(connectTime);
|
139 | var result = await oada.connect({
|
140 | domain,
|
141 | token: "def",
|
142 | websocket: false,
|
143 | cache: false
|
144 | })
|
145 | connections[3] = result;
|
146 | expect(result).to.have.keys([
|
147 | "token",
|
148 | "cache",
|
149 | "websocket",
|
150 | "disconnect",
|
151 | "get",
|
152 | "reconnect",
|
153 | "put",
|
154 | "post",
|
155 | "delete",
|
156 | "resetCache"
|
157 | ]);
|
158 | expect(result.cache).to.equal(false);
|
159 | expect(result.websocket).to.equal(false);
|
160 | expect(result.get).to.be.a("function");
|
161 | expect(result.put).to.be.a("function");
|
162 | expect(result.post).to.be.a("function");
|
163 | expect(result.resetCache).to.be.a("function");
|
164 | expect(result.disconnect).to.be.a("function");
|
165 | });
|
166 |
|
167 | it("Should not make a connection without domain", async function() {
|
168 | this.timeout(connectTime);
|
169 | expect(
|
170 | oada.connect({
|
171 | token: "def",
|
172 | websocket: false,
|
173 | cache: false
|
174 | })
|
175 | ).to.be.rejectedWith(Error, "domain undefined");
|
176 | });
|
177 |
|
178 | it("Should not make a connection without options and token", async function() {
|
179 | this.timeout(connectTime);
|
180 | await expect(
|
181 | oada.connect({
|
182 | domain,
|
183 | websocket: false,
|
184 | cache: false
|
185 | })
|
186 | ).to.be.rejectedWith(Error, "options and token undefined");
|
187 | });
|
188 |
|
189 | it("Should not make a connection if token provided but not a string", async function() {
|
190 | this.timeout(connectTime);
|
191 | await expect(
|
192 | oada.connect({
|
193 | domain,
|
194 | token: { def: "def" },
|
195 | websocket: false,
|
196 | cache: false
|
197 | })
|
198 | ).to.be.rejectedWith(Error, "token must be a string");
|
199 | });
|
200 |
|
201 | it("Should not make a connection if websocket provided but not a boolean", async function() {
|
202 | this.timeout(connectTime);
|
203 | await expect(
|
204 | oada.connect({
|
205 | domain,
|
206 | token: "def",
|
207 | websocket: "false"
|
208 | })
|
209 | ).to.be.rejectedWith(Error, "websocket must be boolean");
|
210 | });
|
211 |
|
212 | it("Should not make a connection if cache provided but not a boolean", async function() {
|
213 | this.timeout(connectTime);
|
214 | await expect(
|
215 | oada.connect({
|
216 | domain,
|
217 | token: "def",
|
218 | cache: "false"
|
219 | })
|
220 | ).to.be.rejectedWith(Error, `cache must be either a boolean or an object with 'name' and/or 'expires' keys`);
|
221 | });
|
222 |
|
223 |
|
224 | |
225 |
|
226 |
|
227 | for (let i = 0; i < connections.length; i++) {
|
228 | describe(`Disconnecting connection ${i + 1}`, function() {
|
229 | it("Should disconnect", async () => {
|
230 | connections[i].disconnect();
|
231 | });
|
232 | });
|
233 | }
|
234 | });
|