Skip to content

Commit 7d14c60

Browse files
committed
Fixed tests, removed extra code
1 parent e821bae commit 7d14c60

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

spec/providers/datastore.spec.ts

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -87,56 +87,60 @@ describe('Datastore Functions', () => {
8787
});
8888

8989
describe('dataConstructor', () => {
90-
function testEvent() {
90+
function constructData(oldValue: object, value: object) {
9191
return {
9292
'data': {
93-
'oldValue': {
94-
'fields': {
95-
'key1': {
96-
'booleanValue': false,
97-
},
98-
'key2': {
99-
'integerValue': '111',
100-
},
101-
},
93+
'oldValue': oldValue,
94+
'value': value,
95+
},
96+
};
97+
}
98+
99+
function createOldValue() {
100+
return {
101+
'fields': {
102+
'key1': {
103+
'booleanValue': false,
102104
},
103-
'value': {
104-
'fields': {
105-
'key1': {
106-
'booleanValue': true,
107-
},
108-
'key2': {
109-
'integerValue': '123',
110-
},
111-
},
105+
'key2': {
106+
'integerValue': '111',
107+
},
108+
},
109+
};
110+
}
111+
112+
function createValue() {
113+
return {
114+
'fields': {
115+
'key1': {
116+
'booleanValue': true,
117+
},
118+
'key2': {
119+
'integerValue': '123',
112120
},
113121
},
114122
};
115123
}
116124

117125
it('constructs appropriate fields and getters for event.data on "document.write" events', () => {
118126
let testFunction = datastore.document('path').onWrite((event) => {
119-
console.log(testEvent());
120-
console.log(event);
121-
console.log(JSON.stringify(event));
122127
expect(event.data.data()).to.deep.equal({key1: true, key2: 123});
123128
expect(event.data.get('key1')).to.equal(true);
124129
expect(event.data.previous.data()).to.deep.equal({key1: false, key2: 111});
125130
expect(event.data.previous.get('key1')).to.equal(false);
126131
});
127-
return testFunction(testEvent());
132+
let data = constructData(createOldValue(), createValue());
133+
return testFunction(data);
128134
});
129135

130136
it('constructs appropriate fields and getters for event.data on "document.create" events', () => {
131137
let testFunction = datastore.document('path').onCreate((event) => {
132138
expect(event.data.data()).to.deep.equal({key1: true, key2: 123});
133139
expect(event.data.get('key1')).to.equal(true);
134-
expect(event.data.previous.data()).to.deep.equal({});
135-
expect(event.data.previous.get('key1')).to.equal(null);
140+
expect(event.data.previous).to.equal(null);
136141
});
137-
let event = testEvent();
138-
event.data.oldValue = null;
139-
return testFunction(event);
142+
let data = constructData(null, createValue());
143+
return testFunction(data);
140144
});
141145

142146
it('constructs appropriate fields and getters for event.data on "document.update" events', () => {
@@ -146,7 +150,8 @@ describe('Datastore Functions', () => {
146150
expect(event.data.previous.data()).to.deep.equal({key1: false, key2: 111});
147151
expect(event.data.previous.get('key1')).to.equal(false);
148152
});
149-
return testFunction(testEvent());
153+
let data = constructData(createOldValue(), createValue());
154+
return testFunction(data);
150155
});
151156

152157
it('constructs appropriate fields and getters for event.data on "document.delete" events', () => {
@@ -156,9 +161,8 @@ describe('Datastore Functions', () => {
156161
expect(event.data.previous.data()).to.deep.equal({key1: false, key2: 111});
157162
expect(event.data.previous.get('key1')).to.equal(false);
158163
});
159-
let event = testEvent();
160-
event.data.value = null;
161-
return testFunction(event);
164+
let data = constructData(createOldValue(), null);
165+
return testFunction(data);
162166
});
163167
});
164168

src/providers/datastore.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ export class DeltaDocumentSnapshot {
135135
return _.get(this.data(), key, null);
136136
}
137137

138+
// Note: this is an expected assymetry between event.data and
139+
// event.data.previous until we move the latter to event.previous
138140
get previous(): DeltaDocumentSnapshot {
139141
if (_.isEmpty(this._old)) {
140142
return null;

0 commit comments

Comments
 (0)