Skip to content

Commit

Permalink
fix: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Agnes Lin committed Jun 30, 2020
1 parent f2cef0f commit 78e7970
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions test/objectid.test.js
Expand Up @@ -11,6 +11,7 @@ let Book, Chapter;
const ds = global.getDataSource();
const objectIDLikeString = '7cd2ad46ffc580ba45d3cb1f';
const objectIDLikeString2 = '7cd2ad46ffc580ba45d3cb1e';
const promisify = require('bluebird').promisify;

describe('ObjectID', function() {
before(function() {
Expand Down Expand Up @@ -135,12 +136,16 @@ describe('ObjectID', function() {
xidArr: [objectIDLikeString, objectIDLikeString2],
title: 'arrayOfObjectID',
});
const found = await Article.findOne({where: {title: 'arrayOfObjectID'}});
const found = await Article.find({where: {title: 'arrayOfObjectID'}});
// the type of the returned array is actually string even it's stored as ObjectIds in the db as expected
found.xidArr.should.be.an.Array().which.containDeep([
found[0].xidArr.should.containDeep([
new ds.ObjectID(objectIDLikeString),
new ds.ObjectID(objectIDLikeString2),
]);
// check if the array is stored in ObjectId
const raw = await findRawModelDataAsync('ArticleC', found[0].id);
raw.xidArr[0].should.be.an.instanceOf(ds.ObjectID);
raw.xidArr[1].should.be.an.instanceOf(ds.ObjectID);
});

it('handles auto-generated PK properties defined in LB4 style', async () => {
Expand Down Expand Up @@ -193,4 +198,8 @@ describe('ObjectID', function() {
found.xidArr.should.be.an.Array().which.containDeep([new ds.ObjectID(objectIDLikeString)]);
});
});
function findRawModelData(modelName, id, cb) {
ds.connector.execute(modelName, 'findOne', {_id: {$eq: id}}, {safe: true}, cb);
}
const findRawModelDataAsync = promisify(findRawModelData);
});

0 comments on commit 78e7970

Please sign in to comment.