-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathpouch-default-change-watcher-test.js
More file actions
186 lines (162 loc) · 6.23 KB
/
pouch-default-change-watcher-test.js
File metadata and controls
186 lines (162 loc) · 6.23 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import { test } from 'qunit';
import moduleForIntegration from '../../helpers/module-for-acceptance';
import { promiseToRunLater } from '../../helpers/async';
import Ember from 'ember';
/*
* Tests for the default automatic change listener.
*/
moduleForIntegration('Integration | Adapter | Default Change Watcher', {
beforeEach(assert) {
var done = assert.async();
Ember.RSVP.Promise.resolve().then(() => {
return this.db().bulkDocs([
{ _id: 'tacoSoup_2_A', data: { flavor: 'al pastor', ingredients: ['X', 'Y'] } },
{ _id: 'tacoSoup_2_B', data: { flavor: 'black bean', ingredients: ['Z'] } },
{ _id: 'foodItem_2_X', data: { name: 'pineapple' } },
{ _id: 'foodItem_2_Y', data: { name: 'pork loin' } },
{ _id: 'foodItem_2_Z', data: { name: 'black beans' } }
]);
}).finally(done);
}
});
test('a loaded instance automatically reflects directly-made database changes', function (assert) {
assert.expect(2);
var done = assert.async();
Ember.RSVP.resolve().then(() => {
return this.store().find('taco-soup', 'B');
}).then((soupB) => {
assert.equal('black bean', soupB.get('flavor'),
'the loaded instance should reflect the initial test data');
return this.db().get('tacoSoup_2_B');
}).then((soupBRecord) => {
soupBRecord.data.flavor = 'carnitas';
return this.db().put(soupBRecord);
}).then(() => {
return promiseToRunLater(() => {
var alreadyLoadedSoupB = this.store().peekRecord('taco-soup', 'B');
assert.equal(alreadyLoadedSoupB.get('flavor'), 'carnitas',
'the loaded instance should automatically reflect the change in the database');
}, 15);
}).finally(done);
});
test('a record that is not loaded stays not loaded when it is changed', function (assert) {
assert.expect(2);
var done = assert.async();
Ember.RSVP.resolve().then(() => {
assert.equal(null, this.store().peekRecord('taco-soup', 'A'),
'test setup: record should not be loaded already');
return this.db().get('tacoSoup_2_A');
}).then((soupARecord) => {
soupARecord.data.flavor = 'barbacoa';
return this.db().put(soupARecord);
}).then(() => {
return promiseToRunLater(() => {
assert.equal(null, this.store().peekRecord('taco-soup', 'A'),
'the corresponding instance should still not be loaded');
}, 15);
}).finally(done);
});
test('a new record is not automatically loaded', function (assert) {
assert.expect(2);
var done = assert.async();
Ember.RSVP.resolve().then(() => {
assert.equal(null, this.store().peekRecord('taco-soup', 'C'),
'test setup: record should not be loaded already');
return this.db().put({
_id: 'tacoSoup_2_C', data: { flavor: 'sofritas' }
});
}).then(() => {
return promiseToRunLater(() => {
assert.equal(null, this.store().peekRecord('taco-soup', 'C'),
'the corresponding instance should still not be loaded');
}, 15);
}).finally(done);
});
test('a deleted record is automatically unloaded', function (assert) {
assert.expect(2);
var done = assert.async();
Ember.RSVP.resolve().then(() => {
return this.store().find('taco-soup', 'B');
}).then((soupB) => {
assert.equal('black bean', soupB.get('flavor'),
'the loaded instance should reflect the initial test data');
return this.db().get('tacoSoup_2_B');
}).then((soupBRecord) => {
return this.db().remove(soupBRecord);
}).then(() => {
return promiseToRunLater(() => {
assert.equal(null, this.store().peekRecord('taco-soup', 'B'),
'the corresponding instance should no longer be loaded');
}, 15);
}).finally(done);
});
test('a change to a record with a non-relational-pouch ID does not cause an error', function (assert) {
assert.expect(0);
var done = assert.async();
Ember.RSVP.resolve().then(() => {
// do some op to cause relational-pouch to be initialized
return this.store().find('taco-soup', 'B');
}).then(() => {
return this.db().put({
_id: '_design/ingredient-use'
});
}).finally(done);
});
test('a change to a record of an unknown type does not cause an error', function (assert) {
assert.expect(0);
var done = assert.async();
Ember.RSVP.resolve().then(() => {
// do some op to cause relational-pouch to be initialized
return this.store().find('taco-soup', 'B');
}).then(() => {
return this.db().put({
_id: 'burritoShake_2_X', data: { consistency: 'chunky' }
});
}).finally(done);
});
moduleForIntegration('Integration | Adapter | With unloadedDocumentChanged implementation to load new docs into store', {
beforeEach(assert) {
var done = assert.async();
this.adapter = function adapter() {
return this.store().adapterFor('taco-salad');
};
this.db = function db() {
return this.adapter().get('db');
};
Ember.RSVP.Promise.resolve().then(() => {
return this.db().bulkDocs([
{ _id: 'tacoSalad_2_A', data: { flavor: 'al pastor', ingredients: ['X', 'Y'] } },
{ _id: 'tacoSalad_2_B', data: { flavor: 'black bean', ingredients: ['Z'] } },
{ _id: 'foodItem_2_X', data: { name: 'pineapple' } },
{ _id: 'foodItem_2_Y', data: { name: 'pork loin' } },
{ _id: 'foodItem_2_Z', data: { name: 'black beans' } }
]);
}).finally(done);
}
});
test('a new record is automatically loaded', function (assert) {
assert.expect(4);
var done = assert.async();
Ember.RSVP.resolve().then(() => {
return this.store().find('taco-salad', 'B');
}).then((soupB) => {
assert.equal('black bean', soupB.get('flavor'),
'the loaded instance should reflect the initial test data');
}).then(() => {
assert.equal(null, this.store().peekRecord('taco-salad', 'C'),
'test setup: record should not be loaded already');
return this.db().put({
_id: 'tacoSalad_2_C', data: { flavor: 'sofritas' }
});
}).then(() => {
return promiseToRunLater(() => {
var alreadyLoadedSaladC = this.store().peekRecord('taco-salad', 'C');
assert.ok(alreadyLoadedSaladC,
'the corresponding instance should now be loaded');
if (alreadyLoadedSaladC) {
assert.equal(alreadyLoadedSaladC.get('flavor'), 'sofritas',
'the corresponding instance should now be loaded with the right data');
}
}, 15);
}).finally(done);
});