1 | process.env.NODE_TLS_REJECT_UNAUTHORIZED=0
|
2 | import Promise from 'bluebird'
|
3 | import oada from '../src/index'
|
4 | import chai from 'chai';
|
5 | var expect = chai.expect;
|
6 |
|
7 | let token = 'def';
|
8 | let domain = 'https://vip3.ecn.purdue.edu';
|
9 | let connOne;
|
10 | let connTwo;
|
11 | let contentType = 'application/vnd.oada.yield.1+json';
|
12 | let connectTime = 30 * 1000;
|
13 |
|
14 | let tree = {
|
15 | 'bookmarks': {
|
16 | '_type': 'application/vnd.oada.bookmarks.1+json',
|
17 | '_rev': '0-0',
|
18 | 'test': {
|
19 | '_type': 'application/vnd.oada.harvest.1+json',
|
20 | '_rev': '0-0',
|
21 | 'aaa': {
|
22 | '_type': 'application/vnd.oada.as-harvested.1+json',
|
23 | '_rev': '0-0',
|
24 | 'index-one': {
|
25 | '*': {
|
26 | '_type': 'application/vnd.oada.as-harvested.yield-moisture-dataset.1+json',
|
27 | '_rev': 'application/vnd.oada.as-harvested.yield-moisture-dataset.1+json',
|
28 | }
|
29 | }
|
30 | }
|
31 | }
|
32 | }
|
33 | }
|
34 |
|
35 | describe('~~~~~~~~~~~WATCH TESTING~~~~~~~~~~~~~~', function() {
|
36 | this.timeout(9000);
|
37 | it('Make the first connection.', function() {
|
38 | this.timeout(connectTime);
|
39 | return oada.connect({
|
40 | domain,
|
41 | token: 'def',
|
42 | cache: {name: 'testOne'},
|
43 | }).then((result) => {
|
44 | connOne = result;
|
45 | expect(result).to.have.keys(['token', 'cache', 'socket', 'disconnect', 'get', 'put', 'post', 'delete', 'resetCache'])
|
46 | expect(result.cache).to.not.equal(undefined);
|
47 | expect(result.socket).to.not.equal(undefined);
|
48 | return connOne.resetCache().then(() => {
|
49 | return connOne.delete({path:'/bookmarks/test'})
|
50 | })
|
51 | })
|
52 | })
|
53 |
|
54 | it('PUT some initial state onto the server + first cache.', () => {
|
55 | return connOne.put({
|
56 | path: '/bookmarks/test/aaa/index-one/ccc/happy',
|
57 | type: 'application/vnd.oada.yield.1+json',
|
58 | data: `"456"`,
|
59 | tree,
|
60 | }).then((response) => {
|
61 | expect(response.headers).to.include.keys(['content-location', 'x-oada-rev', 'location'])
|
62 | })
|
63 | })
|
64 |
|
65 | it(`GET and commence a watch on the first connection.`, function() {
|
66 | this.timeout(5000);
|
67 | let payload = { pay: 'load' };
|
68 | return connOne.get({
|
69 | path: '/bookmarks/test',
|
70 | watch: {
|
71 | func: (payload) => {
|
72 | |
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | },
|
83 | payload
|
84 | }
|
85 | }).then((response) => {
|
86 | expect(response.status).to.equal(200)
|
87 | expect(response.headers).to.include.keys(['content-location', 'x-oada-rev'])
|
88 | })
|
89 | })
|
90 |
|
91 | it('Make a second connection.', function() {
|
92 | this.timeout(connectTime);
|
93 | return oada.connect({
|
94 | domain,
|
95 | token: 'def',
|
96 | cache: {name: 'testTwo'}
|
97 | }).then((result) => {
|
98 | connTwo = result;
|
99 | expect(result).to.have.keys(['token', 'cache', 'socket', 'disconnect', 'get', 'put', 'post', 'delete', 'resetCache'])
|
100 | expect(result.cache).to.not.equal(undefined);
|
101 | expect(result.socket).to.not.equal(undefined);
|
102 | return connTwo.resetCache();
|
103 | })
|
104 | })
|
105 |
|
106 | it(`PUT over the second connection and check that the first received it.`, ()=> {
|
107 | return connTwo.put({
|
108 | path: '/bookmarks/test/aaa/index-one/eee',
|
109 | type: 'application/vnd.oada.as-harvested.yield-moisture.dataset.1+json',
|
110 | tree,
|
111 | data: {some: 'test'},
|
112 | }).then((response) => {
|
113 | expect(response.status).to.equal(204)
|
114 | expect(response.headers).to.include.keys(['content-location', 'x-oada-rev', 'location'])
|
115 | return connOne.get({
|
116 | path: '/bookmarks/test/aaa/index-one/eee',
|
117 | }).then((res) => {
|
118 | expect(res.data).to.include.key('some')
|
119 | expect(res.data.some).to.equal('test')
|
120 | expect(res.cached).to.equal(true);
|
121 | return connOne.get({
|
122 | path: '/bookmarks/test',
|
123 | }).then((res) => {
|
124 | expect(res.cached).to.equal(true)
|
125 | return connOne.get({
|
126 | path: '/bookmarks/test/aaa',
|
127 | }).then((res) => {
|
128 | expect(res.cached).to.equal(true)
|
129 | return connOne.get({
|
130 | path: '/bookmarks/test/aaa/index-one',
|
131 | }).then((res) => {
|
132 | expect(res.cached).to.equal(true)
|
133 | })
|
134 | })
|
135 | })
|
136 | })
|
137 | })
|
138 | })
|
139 |
|
140 | it('Now clean up', () => {
|
141 | return connOne.delete({
|
142 | path: '/bookmarks/test',
|
143 | }).then(() => {
|
144 | return connOne.disconnect();
|
145 | })
|
146 | })
|
147 |
|
148 | it('Now clean up', () => {
|
149 | return connTwo.delete({
|
150 | path: '/bookmarks/test',
|
151 | }).then(() => {
|
152 | return connTwo.disconnect();
|
153 | })
|
154 | })
|
155 | })
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|