Skip to content

Commit 966c0f7

Browse files
committed
Use more informative column names in ModelMapper tests
1 parent ae80fd0 commit 966c0f7

File tree

1 file changed

+82
-82
lines changed

1 file changed

+82
-82
lines changed

test/unit/mapping/model-mapper-mutation-tests.js

Lines changed: 82 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,35 @@ describe('ModelMapper', () => {
2828
mapperTestHelper.testParameters('insert');
2929

3030
it('should retrieve the table that apply and make a single execution', () => {
31-
const clientInfo = mapperTestHelper.getClient([ 'id1', 'id2', 'name'], [ 1, 1 ]);
31+
const clientInfo = mapperTestHelper.getClient([ 'partition1', 'clustering1', 'name'], [ 1, 1 ]);
3232
const modelMapper = mapperTestHelper.getModelMapper(clientInfo);
33-
const doc = { id2: 'value2' , id1: 'value1' };
33+
const doc = { clustering1: 'value2' , partition1: 'value1' };
3434

3535
return modelMapper.insert(doc)
3636
.then(() => {
3737
assert.strictEqual(clientInfo.executions.length, 1);
3838
const execution = clientInfo.executions[0];
39-
assert.strictEqual(execution.query, 'INSERT INTO ks1.table1 ("id2", "id1") VALUES (?, ?)');
39+
assert.strictEqual(execution.query, 'INSERT INTO ks1.table1 ("clustering1", "partition1") VALUES (?, ?)');
4040
assert.deepStrictEqual(execution.params, Object.keys(doc).map(key => doc[key]));
4141
helper.assertProperties(execution.options, { prepare: true, isIdempotent: true });
4242
});
4343
});
4444

4545
it('should mark LWT queries as non-idempotent', () => testQueries('insert', [
4646
{
47-
doc: { id2: 'value2' , id1: 'value1', name: 'name1' },
47+
doc: { clustering1: 'value2' , partition1: 'value1', name: 'name1' },
4848
docInfo: { ifNotExists: true },
49-
query: 'INSERT INTO ks1.table1 ("id2", "id1", "name") VALUES (?, ?, ?) IF NOT EXISTS',
49+
query: 'INSERT INTO ks1.table1 ("clustering1", "partition1", "name") VALUES (?, ?, ?) IF NOT EXISTS',
5050
params: [ 'value2', 'value1', 'name1' ],
5151
isIdempotent: false
5252
}
5353
]));
5454

5555
it('should set TTL', () => testQueries('insert', [
5656
{
57-
doc: { id2: 'value2' , id1: 'value1', name: 'name1' },
57+
doc: { clustering1: 'value2' , partition1: 'value1', name: 'name1' },
5858
docInfo: { ttl: 1000 },
59-
query: 'INSERT INTO ks1.table1 ("id2", "id1", "name") VALUES (?, ?, ?) USING TTL ?',
59+
query: 'INSERT INTO ks1.table1 ("clustering1", "partition1", "name") VALUES (?, ?, ?) USING TTL ?',
6060
params: [ 'value2', 'value1', 'name1', 1000 ]
6161
}
6262
]));
@@ -75,7 +75,7 @@ describe('ModelMapper', () => {
7575

7676
let catchCalled = false;
7777

78-
return modelMapper.insert({ id1: 'value1' })
78+
return modelMapper.insert({ partition1: 'value1' })
7979
.catch(err => {
8080
catchCalled = true;
8181
assert.strictEqual(err, error);
@@ -85,30 +85,30 @@ describe('ModelMapper', () => {
8585

8686
it('should throw an error when filter or conditions are not valid', () => testErrors('insert', [
8787
{
88-
doc: { id1: 'x', notAValidProp: 'y' },
89-
message: 'No table matches (all PKs have to be specified) fields: [id1,notAValidProp]'
88+
doc: { partition1: 'x', notAValidProp: 'y' },
89+
message: 'No table matches (all PKs have to be specified) fields: [partition1,notAValidProp]'
9090
}, {
91-
doc: { id1: 'x'},
91+
doc: { partition1: 'x'},
9292
docInfo: { fields: ['notAValidProp'] },
9393
message: 'No table matches (all PKs have to be specified) fields: [notAValidProp]'
9494
}, {
95-
doc: { id1: 'x', name: 'y' },
96-
message: 'No table matches (all PKs have to be specified) fields: [id1,name]'
95+
doc: { partition1: 'x', name: 'y' },
96+
message: 'No table matches (all PKs have to be specified) fields: [partition1,name]'
9797
}, {
9898
doc: {},
9999
message: 'Expected object with keys'
100100
}
101101
]));
102102

103103
it('should warn when cache reaches 100 different queries', async () => {
104-
const clientInfo = mapperTestHelper.getClient(['id1'], [ 1 ], 'ks1');
104+
const clientInfo = mapperTestHelper.getClient(['partition1'], [ 1 ], 'ks1');
105105
const modelMapper = mapperTestHelper.getModelMapper(clientInfo);
106106

107107
const cacheHighWaterMark = 100;
108108
const promises = [];
109109

110110
for (let i = 0; i < 2 * cacheHighWaterMark; i++) {
111-
promises.push(modelMapper.insert({ id1: 1, [`col${i % (cacheHighWaterMark-1)}`]: 1}));
111+
promises.push(modelMapper.insert({ partition1: 1, [`col${i % (cacheHighWaterMark-1)}`]: 1}));
112112
}
113113

114114
await Promise.all(promises);
@@ -117,7 +117,7 @@ describe('ModelMapper', () => {
117117
assert.strictEqual(clientInfo.logMessages.filter(l => l.level === 'warning').length, 0);
118118

119119
// One more query
120-
await modelMapper.insert({ id1: 1, anotherColumn: 1 });
120+
await modelMapper.insert({ partition1: 1, anotherColumn: 1 });
121121

122122
const warnings = clientInfo.logMessages.filter(l => l.level === 'warning');
123123
assert.strictEqual(warnings.length, 1);
@@ -136,9 +136,9 @@ describe('ModelMapper', () => {
136136
},
137137
items: [
138138
{
139-
doc: { id1: 'value_id1', id2: 'value_id2', name: { prop1: 1, prop2: 'two' } },
140-
query: 'INSERT INTO ks1.table1 ("id1", "id2", "name") VALUES (?, ?, ?)',
141-
params: [ 'value_id1', 'value_id2', '{"prop1":1,"prop2":"two"}']
139+
doc: { partition1: 'value_partition1', clustering1: 'value_clustering1', name: { prop1: 1, prop2: 'two' } },
140+
query: 'INSERT INTO ks1.table1 ("partition1", "clustering1", "name") VALUES (?, ?, ?)',
141+
params: [ 'value_partition1', 'value_clustering1', '{"prop1":1,"prop2":"two"}']
142142
}
143143
]
144144
}));
@@ -149,93 +149,93 @@ describe('ModelMapper', () => {
149149

150150
it('should retrieve the table that apply and make a single execution', () => testQueries('update', [
151151
{
152-
doc: { id2: 'value2' , id1: 'value1', name: 'name1' },
153-
query: 'UPDATE ks1.table1 SET "name" = ? WHERE "id2" = ? AND "id1" = ?',
152+
doc: { clustering1: 'value2' , partition1: 'value1', name: 'name1' },
153+
query: 'UPDATE ks1.table1 SET "name" = ? WHERE "clustering1" = ? AND "partition1" = ?',
154154
params: ['name1', 'value2', 'value1'],
155155
isIdempotent: true
156156
}]));
157157

158158
it('should mark LWT queries as non-idempotent', () => testQueries('update', [
159159
{
160-
doc: {id2: 'value2', id1: 'value1', name: 'name1'},
160+
doc: {clustering1: 'value2', partition1: 'value1', name: 'name1'},
161161
docInfo: {when: {name: 'previous name'}},
162-
query: 'UPDATE ks1.table1 SET "name" = ? WHERE "id2" = ? AND "id1" = ? IF "name" = ?',
162+
query: 'UPDATE ks1.table1 SET "name" = ? WHERE "clustering1" = ? AND "partition1" = ? IF "name" = ?',
163163
params: ['name1', 'value2', 'value1', 'previous name'],
164164
isIdempotent: false
165165
}]));
166166

167167
it('should append/prepend to a list', () => testQueries('update', [
168168
{
169-
doc: { id2: 'value2' , id1: 'value1', name: 'name1', list1: q.append(['a', 'b']) },
170-
query: 'UPDATE ks1.table1 SET "name" = ?, "list1" = "list1" + ? WHERE "id2" = ? AND "id1" = ?',
169+
doc: { clustering1: 'value2' , partition1: 'value1', name: 'name1', list1: q.append(['a', 'b']) },
170+
query: 'UPDATE ks1.table1 SET "name" = ?, "list1" = "list1" + ? WHERE "clustering1" = ? AND "partition1" = ?',
171171
params: ['name1', ['a', 'b'], 'value2', 'value1'],
172172
isIdempotent: false
173173
}, {
174-
doc: { id2: 'value2' , id1: 'value1', name: 'name1', list1: q.prepend(['a', 'b']) },
175-
query: 'UPDATE ks1.table1 SET "name" = ?, "list1" = ? + "list1" WHERE "id2" = ? AND "id1" = ?',
174+
doc: { clustering1: 'value2' , partition1: 'value1', name: 'name1', list1: q.prepend(['a', 'b']) },
175+
query: 'UPDATE ks1.table1 SET "name" = ?, "list1" = ? + "list1" WHERE "clustering1" = ? AND "partition1" = ?',
176176
params: ['name1', ['a', 'b'], 'value2', 'value1'],
177177
isIdempotent: false
178178
}]));
179179

180180
it('should increment/decrement a counter', () => {
181-
const clientInfo = mapperTestHelper.getClient([ 'id1', 'id2', { name: 'c1', type: { code: dataTypes.counter }}], [ 1, 1 ]);
181+
const clientInfo = mapperTestHelper.getClient([ 'partition1', 'clustering1', { name: 'c1', type: { code: dataTypes.counter }}], [ 1, 1 ]);
182182
const modelMapper = mapperTestHelper.getModelMapper(clientInfo);
183183
const items = [
184184
{
185-
doc: { id2: 'value2' , id1: 'value1', c1: q.incr(10) },
186-
query: 'UPDATE ks1.table1 SET "c1" = "c1" + ? WHERE "id2" = ? AND "id1" = ?'
185+
doc: { clustering1: 'value2' , partition1: 'value1', c1: q.incr(10) },
186+
query: 'UPDATE ks1.table1 SET "c1" = "c1" + ? WHERE "clustering1" = ? AND "partition1" = ?'
187187
}, {
188-
doc: { id2: 'another id 2' , id1: 'another id 1', c1: q.decr(10) },
189-
query: 'UPDATE ks1.table1 SET "c1" = "c1" - ? WHERE "id2" = ? AND "id1" = ?'
188+
doc: { clustering1: 'another id 2' , partition1: 'another id 1', c1: q.decr(10) },
189+
query: 'UPDATE ks1.table1 SET "c1" = "c1" - ? WHERE "clustering1" = ? AND "partition1" = ?'
190190
}];
191191

192192
return Promise.all(items.map((item, index) => modelMapper.update(item.doc).then(() => {
193193
assert.strictEqual(clientInfo.executions.length, items.length);
194194
const execution = clientInfo.executions[index];
195195
assert.strictEqual(execution.query, item.query);
196-
assert.deepStrictEqual(execution.params, [ 10, item.doc.id2, item.doc.id1 ]);
196+
assert.deepStrictEqual(execution.params, [ 10, item.doc.clustering1, item.doc.partition1 ]);
197197
helper.assertProperties(execution.options, { prepare: true, isIdempotent: false });
198198
})));
199199
});
200200

201201
it('should throw an error when filter or conditions are not valid', () => testErrors('update', [
202202
{
203-
doc: { id1: 'x', notAValidProp: 'y' },
204-
message: 'No table matches (all PKs and columns to set have to be specified) fields: [id1,notAValidProp]'
203+
doc: { partition1: 'x', notAValidProp: 'y' },
204+
message: 'No table matches (all PKs and columns to set have to be specified) fields: [partition1,notAValidProp]'
205205
}, {
206-
doc: { id1: 'x'},
206+
doc: { partition1: 'x'},
207207
docInfo: { fields: ['notAValidProp'] },
208208
message: 'No table matches (all PKs and columns to set have to be specified) fields: [notAValidProp]'
209209
}, {
210-
doc: { id1: 'x', name: 'y' },
211-
message: 'No table matches (all PKs and columns to set have to be specified) fields: [id1,name]'
210+
doc: { partition1: 'x', name: 'y' },
211+
message: 'No table matches (all PKs and columns to set have to be specified) fields: [partition1,name]'
212212
}, {
213-
doc: { id1: 'x', id2: 'y', name: 'z'},
213+
doc: { partition1: 'x', clustering1: 'y', name: 'z'},
214214
docInfo: { when: { notAValidProp: 'm'} },
215-
message: 'No table matches (all PKs and columns to set have to be specified) fields: [id1,id2,name]; condition: [notAValidProp]'
215+
message: 'No table matches (all PKs and columns to set have to be specified) fields: [partition1,clustering1,name]; condition: [notAValidProp]'
216216
}, {
217217
doc: {},
218218
message: 'Expected object with keys'
219219
}, {
220-
doc: { id1: 'x', id2: 'y' },
221-
message: 'No table matches (all PKs and columns to set have to be specified) fields: [id1,id2]'
220+
doc: { partition1: 'x', clustering1: 'y' },
221+
message: 'No table matches (all PKs and columns to set have to be specified) fields: [partition1,clustering1]'
222222
}
223223
]));
224224

225225
it('should use fields when specified', () => testQueries('update', [
226226
{
227-
doc: { id2: 'value2', id1: 'value1', name: 'name1', description: 'description1' },
228-
docInfo: { fields: [ 'id1', 'id2', 'description' ] },
229-
query: 'UPDATE ks1.table1 SET "description" = ? WHERE "id1" = ? AND "id2" = ?',
227+
doc: { clustering1: 'value2', partition1: 'value1', name: 'name1', description: 'description1' },
228+
docInfo: { fields: [ 'partition1', 'clustering1', 'description' ] },
229+
query: 'UPDATE ks1.table1 SET "description" = ? WHERE "partition1" = ? AND "clustering1" = ?',
230230
params: ['description1', 'value1', 'value2']
231231
}]));
232232

233233
it('should set TTL', () => testQueries('update', [
234234
{
235-
doc: { id1: 'value_id1', id2: 'value_id2', name: 'value_name1' },
235+
doc: { partition1: 'value_partition1', clustering1: 'value_clustering1', name: 'value_name1' },
236236
docInfo: { ttl: 360 },
237-
query: 'UPDATE ks1.table1 USING TTL ? SET "name" = ? WHERE "id1" = ? AND "id2" = ?',
238-
params: [ 360, 'value_name1', 'value_id1', 'value_id2' ]
237+
query: 'UPDATE ks1.table1 USING TTL ? SET "name" = ? WHERE "partition1" = ? AND "clustering1" = ?',
238+
params: [ 360, 'value_name1', 'value_partition1', 'value_clustering1' ]
239239
}
240240
]));
241241

@@ -246,21 +246,21 @@ describe('ModelMapper', () => {
246246
tables: ['table1'],
247247
columns: {
248248
'name': { fromModel: JSON.stringify },
249-
'id2': { fromModel: v => v + "_suffix" }
249+
'clustering1': { fromModel: v => v + "_suffix" }
250250
}
251251
}
252252
},
253253
items: [
254254
{
255-
doc: { id1: 'value_id1', id2: 'value_id2', name: { prop1: 1, prop2: 'two' } },
256-
query: 'UPDATE ks1.table1 SET "name" = ? WHERE "id1" = ? AND "id2" = ?',
257-
params: [ '{"prop1":1,"prop2":"two"}', 'value_id1', 'value_id2_suffix' ]
255+
doc: { partition1: 'value_partition1', clustering1: 'value_clustering1', name: { prop1: 1, prop2: 'two' } },
256+
query: 'UPDATE ks1.table1 SET "name" = ? WHERE "partition1" = ? AND "clustering1" = ?',
257+
params: [ '{"prop1":1,"prop2":"two"}', 'value_partition1', 'value_clustering1_suffix' ]
258258
},
259259
{
260-
doc: { id1: 'value_id1', id2: 'value_id2', description: 'my description' },
260+
doc: { partition1: 'value_partition1', clustering1: 'value_clustering1', description: 'my description' },
261261
docInfo: { when: { name: { a: 'a', b: 2 } } },
262-
query: 'UPDATE ks1.table1 SET "description" = ? WHERE "id1" = ? AND "id2" = ? IF "name" = ?',
263-
params: [ 'my description', 'value_id1', 'value_id2_suffix', '{"a":"a","b":2}' ],
262+
query: 'UPDATE ks1.table1 SET "description" = ? WHERE "partition1" = ? AND "clustering1" = ? IF "name" = ?',
263+
params: [ 'my description', 'value_partition1', 'value_clustering1_suffix', '{"a":"a","b":2}' ],
264264
isIdempotent: false
265265
}
266266
]
@@ -272,49 +272,49 @@ describe('ModelMapper', () => {
272272

273273
it('should throw an error when filter or conditions are not valid', () => testErrors('remove', [
274274
{
275-
doc: { id1: 'x', notAValidProp: 'y' },
276-
message: 'No table matches (must specify all partition key and top-level clustering columns) fields: [id1,notAValidProp]'
275+
doc: { partition1: 'x', notAValidProp: 'y' },
276+
message: 'No table matches (must specify all partition key and top-level clustering columns) fields: [partition1,notAValidProp]'
277277
}, {
278-
doc: { id1: 'x'},
278+
doc: { partition1: 'x'},
279279
docInfo: { fields: ['notAValidProp'] },
280280
message: 'No table matches (must specify all partition key and top-level clustering columns) fields: [notAValidProp]'
281281
}, {
282-
doc: { id1: 'x', name: 'y' },
283-
message: 'No table matches (must specify all partition key and top-level clustering columns) fields: [id1,name]'
282+
doc: { partition1: 'x', name: 'y' },
283+
message: 'No table matches (must specify all partition key and top-level clustering columns) fields: [partition1,name]'
284284
}, {
285-
doc: { id1: 'x', id2: 'y'},
285+
doc: { partition1: 'x', clustering1: 'y'},
286286
docInfo: { when: { notAValidProp: 'm'} },
287-
message: 'No table matches (must specify all partition key and top-level clustering columns) fields: [id1,id2]; condition: [notAValidProp]'
287+
message: 'No table matches (must specify all partition key and top-level clustering columns) fields: [partition1,clustering1]; condition: [notAValidProp]'
288288
}, {
289289
doc: {},
290290
message: 'Expected object with keys'
291291
}, {
292-
doc: { id1: 'x', id3: 'y' },
293-
message: 'No table matches (must specify all partition key and top-level clustering columns) fields: [id1,id3]'
292+
doc: { partition1: 'x', clustering2: 'y' },
293+
message: 'No table matches (must specify all partition key and top-level clustering columns) fields: [partition1,clustering2]'
294294
}
295295
]));
296296

297297
it('should generate the query, params and set the idempotency', () => testQueries('remove', [
298298
{
299-
doc: { id1: 'x', id2: 'y' },
300-
query: 'DELETE FROM ks1.table1 WHERE "id1" = ? AND "id2" = ?',
299+
doc: { partition1: 'x', clustering1: 'y' },
300+
query: 'DELETE FROM ks1.table1 WHERE "partition1" = ? AND "clustering1" = ?',
301301
params: [ 'x', 'y' ]
302302
}, {
303-
doc: { id1: 'x', id2: 'y' },
303+
doc: { partition1: 'x', clustering1: 'y' },
304304
docInfo: { when: { name: 'a' }},
305-
query: 'DELETE FROM ks1.table1 WHERE "id1" = ? AND "id2" = ? IF "name" = ?',
305+
query: 'DELETE FROM ks1.table1 WHERE "partition1" = ? AND "clustering1" = ? IF "name" = ?',
306306
params: [ 'x', 'y', 'a' ],
307307
isIdempotent: false
308308
}, {
309-
doc: { id1: 'x', id2: 'y' },
309+
doc: { partition1: 'x', clustering1: 'y' },
310310
docInfo: { ifExists: true },
311-
query: 'DELETE FROM ks1.table1 WHERE "id1" = ? AND "id2" = ? IF EXISTS',
311+
query: 'DELETE FROM ks1.table1 WHERE "partition1" = ? AND "clustering1" = ? IF EXISTS',
312312
params: [ 'x', 'y' ],
313313
isIdempotent: false
314314
}, {
315-
doc: { id1: 'x', id2: 'y' },
316-
docInfo: { fields: [ 'id1', 'id2', 'name' ], deleteOnlyColumns: true },
317-
query: 'DELETE "name" FROM ks1.table1 WHERE "id1" = ? AND "id2" = ?',
315+
doc: { partition1: 'x', clustering1: 'y' },
316+
docInfo: { fields: [ 'partition1', 'clustering1', 'name' ], deleteOnlyColumns: true },
317+
query: 'DELETE "name" FROM ks1.table1 WHERE "partition1" = ? AND "clustering1" = ?',
318318
params: [ 'x', 'y' ]
319319
}
320320
]));
@@ -326,21 +326,21 @@ describe('ModelMapper', () => {
326326
tables: ['table1'],
327327
columns: {
328328
'name': { fromModel: JSON.stringify },
329-
'id2': { fromModel: v => v + "_suffix" }
329+
'clustering1': { fromModel: v => v + "_suffix" }
330330
}
331331
}
332332
},
333333
items: [
334334
{
335-
doc: { id1: 'value_id1', id2: 'value_id2' },
336-
query: 'DELETE FROM ks1.table1 WHERE "id1" = ? AND "id2" = ?',
337-
params: [ 'value_id1', 'value_id2_suffix' ]
335+
doc: { partition1: 'value_partition1', clustering1: 'value_clustering1' },
336+
query: 'DELETE FROM ks1.table1 WHERE "partition1" = ? AND "clustering1" = ?',
337+
params: [ 'value_partition1', 'value_clustering1_suffix' ]
338338
},
339339
{
340-
doc: { id1: 'value_id1', id2: 'value_id2' },
340+
doc: { partition1: 'value_partition1', clustering1: 'value_clustering1' },
341341
docInfo: { when: { name: { a: 1 } }},
342-
query: 'DELETE FROM ks1.table1 WHERE "id1" = ? AND "id2" = ? IF "name" = ?',
343-
params: [ 'value_id1', 'value_id2_suffix', '{"a":1}' ],
342+
query: 'DELETE FROM ks1.table1 WHERE "partition1" = ? AND "clustering1" = ? IF "name" = ?',
343+
params: [ 'value_partition1', 'value_clustering1_suffix', '{"a":1}' ],
344344
isIdempotent: false
345345
},
346346
]
@@ -350,7 +350,7 @@ describe('ModelMapper', () => {
350350

351351
function testErrors(methodName, items) {
352352
return Promise.all(items.map(item => {
353-
const columns = [ 'id1', 'id2', 'id3', 'name'];
353+
const columns = [ 'partition1', 'clustering1', 'clustering2', 'name'];
354354
const clientInfo = mapperTestHelper.getClient(columns, [ 1, 2 ], 'ks1');
355355
const modelMapper = mapperTestHelper.getModelMapper(clientInfo);
356356

@@ -368,7 +368,7 @@ function testErrors(methodName, items) {
368368

369369
async function testQueries(methodName, items) {
370370
let models = null;
371-
const columns = [ 'id1', 'id2', 'name', { name: 'list1', type: { code: dataTypes.list }}, 'description'];
371+
const columns = [ 'partition1', 'clustering1', 'name', { name: 'list1', type: { code: dataTypes.list }}, 'description'];
372372

373373
if (typeof methodName === 'object') {
374374
// Its an object with properties as parameters

0 commit comments

Comments
 (0)