-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathwithout-live-sync-test.js
More file actions
118 lines (108 loc) · 4 KB
/
without-live-sync-test.js
File metadata and controls
118 lines (108 loc) · 4 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
import Ember from 'ember';
import { test } from 'qunit';
import moduleForIntegration from '../../helpers/module-for-acceptance';
import { promiseToRunLater } from '../../helpers/async';
moduleForIntegration('Integration | Adapter | Without live sync', {
beforeEach(assert) {
var done = assert.async();
this.adapter = function adapter() {
return this.store().adapterFor('hot-sauce');
};
this.db = function db() {
return this.adapter().get('db');
};
Ember.RSVP.Promise.resolve().then(() => {
return this.db().bulkDocs([
{ _id: 'hotSauce_2_A', data: { name: 'Cholula' } },
{ _id: 'hotSauce_2_B', data: { name: 'Melbourne Hot Sauce' } },
]);
}).finally(done);
},
afterEach(assert) {
var done = assert.async();
this.db().destroy().then(() => {
Ember.run(() => this.adapter().destroy());
done();
});
}
});
test('changes are not synced', function (assert) {
assert.expect(2);
var done = assert.async();
Ember.RSVP.resolve().then(() => {
return this.store().find('hot-sauce', 'A');
}).then((hotSauce) => {
assert.equal('Cholula', hotSauce.get('name'),
'the loaded instance should reflect the initial test data');
return this.db().get('hotSauce_2_A');
}).then((hotSauceRecord) => {
hotSauceRecord.data.name = 'Death Sauce';
return this.db().put(hotSauceRecord);
}).then(() => {
return promiseToRunLater(() => {
var alreadyLoadedHotSauce = this.store().peekRecord('hot-sauce', 'A');
assert.equal(alreadyLoadedHotSauce.get('name'), 'Cholula',
'the loaded instance should not automatically reflect the change in the database');
}, 15);
}).finally(done);
});
test('changes can be manually synced', function (assert) {
assert.expect(3);
var done = assert.async();
this.adapter().set('liveSync', false);
Ember.RSVP.resolve().then(() => {
return this.adapter().sync(); // perform initial sync to get update_seq
}).then(() => {
return this.store().find('hot-sauce', 'A');
}).then((hotSauce) => {
assert.equal('Cholula', hotSauce.get('name'),
'the loaded instance should reflect the initial test data');
return this.db().get('hotSauce_2_A');
}).then((hotSauceRecord) => {
hotSauceRecord.data.name = 'Death Sauce';
return this.db().put(hotSauceRecord);
}).then(() => {
return this.store().find('hot-sauce', 'A');
}).then((hotSauce) => {
assert.equal('Cholula', hotSauce.get('name'),
'the loaded instance does not reflect the changes');
return this.adapter().sync();
})
.then(() => {
return promiseToRunLater(() => {
var alreadyLoadedHotSauce = this.store().peekRecord('hot-sauce', 'A');
assert.equal(alreadyLoadedHotSauce.get('name'), 'Death Sauce',
'the loaded instance reflects the change in the database');
}, 500);
}).finally(done);
});
test('changes can be synced periodically', function (assert) {
assert.expect(3);
var done = assert.async();
this.adapter().set('liveSync', false);
Ember.RSVP.resolve().then(() => {
return this.adapter().sync(); // perform initial sync to get update_seq
}).then(() => {
return this.store().find('hot-sauce', 'A');
}).then((hotSauce) => {
assert.equal('Cholula', hotSauce.get('name'),
'the loaded instance should reflect the initial test data');
return this.db().get('hotSauce_2_A');
}).then((hotSauceRecord) => {
hotSauceRecord.data.name = 'Death Sauce';
return this.db().put(hotSauceRecord);
}).then(() => {
return this.store().find('hot-sauce', 'A');
}).then((hotSauce) => {
assert.equal('Cholula', hotSauce.get('name'),
'the loaded instance does not reflect the changes');
this.adapter().set('syncInterval', 100);
})
.then(() => {
return promiseToRunLater(() => {
var alreadyLoadedHotSauce = this.store().peekRecord('hot-sauce', 'A');
assert.equal(alreadyLoadedHotSauce.get('name'), 'Death Sauce',
'the loaded instance reflects the change in the database');
}, 500);
}).finally(done);
});