Skip to content

Commit f4bf47c

Browse files
committed
confirm id is same after replace
1 parent 88eb6a1 commit f4bf47c

2 files changed

Lines changed: 29 additions & 12 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"async": "^3.1.0",
3232
"debug": "^4.1.1",
3333
"loopback-connector": "^4.0.0",
34-
"loopback-ibmdb": "^2.6.0",
34+
"loopback-ibmdb": "^2.6.1",
3535
"strong-globalize": "^5.0.0"
3636
},
3737
"devDependencies": {

test/dashdb.columnName.test.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ process.env.NODE_ENV = 'test';
1111
require('./init.js');
1212
const assert = require('assert');
1313

14-
let id, db, Book;
14+
let bookId, db, Book;
1515
const BOOK_TITLE = 'Rocky I';
1616
const REVISED_BOOK_TITLE = 'Rocky II';
1717

1818
/*
19-
This test suite is to test the changes surrounding the fix
20-
in loopback-ibmdb related to issue :
19+
This test suite is to test the changes surrounding the fixes
20+
in loopback-ibmdb related to issues :
2121
https://github.com/strongloop/loopback-ibmdb/issues/79
22+
https://github.com/strongloop/loopback-ibmdb/issues/84
2223
*/
2324

24-
describe('replaceById with custom column name for id', () => {
25+
describe('replaceById with custom column name for bookId', () => {
2526
// 'table' option specified since we want a table 'BOOK'
2627
// to be created for model 'Book'
2728
const BOOK_TABLE_OPTIONS = {
@@ -56,15 +57,23 @@ describe('replaceById with custom column name for id', () => {
5657
const newBook = await Book.create({title: BOOK_TITLE});
5758
assert(newBook);
5859
assert.equal(newBook.title, BOOK_TITLE);
59-
id = newBook.id;
60-
const updatedBook = await Book.replaceById(id, {title: REVISED_BOOK_TITLE});
60+
// use the bookId (id property) to ensure
61+
// replaceById and find return same value
62+
bookId = newBook.bookId;
63+
// eslint-disable-next-line max-len
64+
const updatedBook = await Book.replaceById(bookId, {title: REVISED_BOOK_TITLE});
6165
assert(updatedBook);
62-
assert.equal(updatedBook.id, id);
66+
assert.equal(updatedBook.bookId, bookId);
6367
assert.equal(updatedBook.title, REVISED_BOOK_TITLE);
68+
// perform a get and see if bookId is still same.
69+
const foundBooks = await Book.find({where: {content: {like: 'Rocky%'}}});
70+
assert(foundBooks);
71+
assert.equal(foundBooks.length, 1);
72+
assert.equal(foundBooks[0].bookId, bookId);
6473
});
6574
});
6675

67-
describe('replaceById with model name for id', () => {
76+
describe('replaceById with model name for bookId', () => {
6877
// No 'table' option specified since we want a table 'Book'
6978
// to be created for model 'Book'
7079

@@ -89,10 +98,18 @@ describe('replaceById with model name for id', () => {
8998
const newBook = await Book.create({title: BOOK_TITLE});
9099
assert(newBook);
91100
assert.equal(newBook.title, BOOK_TITLE);
92-
id = newBook.id;
93-
const updatedBook = await Book.replaceById(id, {title: REVISED_BOOK_TITLE});
101+
// use the bookId (id property) to ensure
102+
// replaceById and find return same value
103+
bookId = newBook.bookId;
104+
// eslint-disable-next-line max-len
105+
const updatedBook = await Book.replaceById(bookId, {title: REVISED_BOOK_TITLE});
94106
assert(updatedBook);
95-
assert.equal(updatedBook.id, id);
107+
assert.equal(updatedBook.bookId, bookId);
96108
assert.equal(updatedBook.title, REVISED_BOOK_TITLE);
109+
// perform a get and see if bookId is still same.
110+
const foundBooks = await Book.find({where: {content: {like: 'Rocky%'}}});
111+
assert(foundBooks);
112+
assert.equal(foundBooks.length, 1);
113+
assert.equal(foundBooks[0].bookId, bookId);
97114
});
98115
});

0 commit comments

Comments
 (0)