UNPKG

5.48 kBJavaScriptView Raw
1process.env.NODE_TLS_REJECT_UNAUTHORIZED=0
2import Promise from 'bluebird'
3import oada from '../src/index'
4import chai from 'chai';
5var expect = chai.expect;
6
7let token = 'def';
8let domain = 'https://vip3.ecn.purdue.edu';
9let connOne;
10let connTwo;
11let contentType = 'application/vnd.oada.yield.1+json';
12let connectTime = 30 * 1000; // seconds to click through oauth
13
14let 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
35describe('~~~~~~~~~~~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 expect(payload).to.include.keys(['pay', 'response', 'request'])
74 expect(payload.pay).to.equal('load')
75 expect(payload.response).to.include.keys(['change'])
76 expect(payload.response.change.type).to.equal('merge');
77 expect(payload.response.change.body).to.include.keys(['_rev', 'aaa'])
78 expect(payload.response.change.body.aaa).to.include.keys(['_rev', 'index-one'])
79 expect(payload.response.change.body.aaa['index-one']).to.include.keys(['eee'])
80 expect(payload.response.change.body.aaa['index-one'].eee).to.include.keys(['_rev'])
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//TODO:
158/*
159describe('Now clean up', () => {
160 it('delete /bookmarks/test', () => {
161 return connOne.delete({path:'/bookmarks/test'})
162 })
163})
164
165describe('some sort of test with unversioned links', () => {
166 it('delete /bookmarks/test', () => {
167 return connOne.delete({path:'/bookmarks/test'})
168 })
169})
170
171
172describe('test confirming that we cannot watch non-resource paths', () => {
173 console.log('it should throw some reasonable error on the server perhaps');
174})
175*/