Skip to content

Commit 918b7c2

Browse files
committed
fix(queryBackUp): desc is empty string when not defined
1 parent fc0c1c9 commit 918b7c2

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

angular-sql-query.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@
463463
var queryOrder = ' ORDER BY ' + sortParams.map(function (_ref) {
464464
var key = _ref.key,
465465
desc = _ref.desc;
466-
return key + ' ' + (desc && 'DESC');
466+
return '' + key + (desc ? ' DESC' : '');
467467
}).join(',');
468468

469469
return query + queryOrder;

angular-sql-query.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/angular-sql-query.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@
488488
}
489489

490490
const queryOrder = ` ORDER BY ${
491-
sortParams.map(({ key, desc }) => `${key} ${desc && 'DESC'}`).join(',')
491+
sortParams.map(({ key, desc }) => `${key}${desc ? ' DESC': ''}`).join(',')
492492
}`;
493493

494494
return query + queryOrder;

src/angular-sql-query.spec.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,24 +217,44 @@
217217

218218
$timeout.flush();
219219

220-
// expect(executeStub.callCount).equal(1);
220+
expect(executeStub.callCount).equal(1);
221221
expect(executeStub.args[0][0]).equal('SELECT * FROM test ORDER BY name DESC LIMIT 10;');
222222

223223
expect(data).lengthOf(1);
224224
expect(data[0].id).equal(1);
225+
}));
225226

226-
// Array param
227-
data = null;
227+
it('should query Backup datas with sort desc', inject((
228+
$q,
229+
$timeout
230+
) => {
231+
executeStub.yields('test', backupDatas);
232+
233+
// Common param
228234
backUp.queryBackUp({
229-
test: ['test1', 'test2'],
230-
}).then((_data_) => {
231-
data = _data_;
235+
test: 'test1',
236+
isOk: false,
237+
}, { limit: 10 }, [{ key: 'name' }]).then((_data_) => {
232238
});
233239
$timeout.flush();
234240

235-
expect(data).lengthOf(2);
236-
expect(data[0].id).equal(1);
237-
expect(data[1].id).equal(2);
241+
expect(executeStub.args[0][0]).equal('SELECT * FROM test ORDER BY name LIMIT 10;');
242+
}));
243+
244+
it('should query Backup datas with multiple sort keys', inject((
245+
$q,
246+
$timeout
247+
) => {
248+
executeStub.yields('test', backupDatas);
249+
250+
// With 2 sort keys
251+
backUp.queryBackUp({
252+
test: 'test1',
253+
isOk: false,
254+
}, { limit: 10 }, [{ key: 'name' }, { key: 'distance' }]);
255+
$timeout.flush();
256+
257+
expect(executeStub.args[0][0]).equal('SELECT * FROM test ORDER BY name,distance LIMIT 10;');
238258
}));
239259

240260
it('should query Backup datas with indexed fields', inject(($q, $timeout) => {

0 commit comments

Comments
 (0)