Merge pull request #1721 from strongloop/fix/failing-tests
test: define models properly
This commit is contained in:
commit
6677c58cff
|
@ -1056,34 +1056,56 @@ describe('basic-querying', function() {
|
|||
});
|
||||
|
||||
describe('updateAll', function() {
|
||||
it('coerces primitive datatypes on update', async () => {
|
||||
const numAndDateModel = db.define('numAndDateModel', {
|
||||
let numAndDateModel, numAndDateArrayModel;
|
||||
|
||||
before(function() {
|
||||
numAndDateModel = db.define('numAndDateModel', {
|
||||
dateProp: Date,
|
||||
dateArray: [Date],
|
||||
numProp: Number,
|
||||
});
|
||||
numAndDateArrayModel = db.define('numAndDateArrayModel', {
|
||||
dateArray: [Date],
|
||||
numArray: [Number],
|
||||
});
|
||||
return db.automigrate(['numAndDateModel', 'numAndDateArrayModel']);
|
||||
});
|
||||
|
||||
it('coerces primitive datatypes on update', async () => {
|
||||
const createDate = new Date('2019-02-21T12:00:00').toISOString();
|
||||
const createData = {
|
||||
dateProp: createDate,
|
||||
dateArray: [createDate, createDate],
|
||||
numProp: '1',
|
||||
numArray: ['1', '2'],
|
||||
};
|
||||
const updateDate = new Date('2019-04-15T12:00:00').toISOString();
|
||||
const updateData = {
|
||||
dateProp: updateDate,
|
||||
dateArray: [updateDate, updateDate],
|
||||
numProp: '3',
|
||||
numArray: ['3', '4'],
|
||||
};
|
||||
const created = await numAndDateModel.create(createData);
|
||||
const updated = await numAndDateModel.updateAll({id: created.id}, updateData);
|
||||
const found = await numAndDateModel.findById(created.id);
|
||||
found.dateProp.should.deepEqual(new Date(updateDate));
|
||||
found.numProp.should.equal(3);
|
||||
});
|
||||
|
||||
// PostgreSQL connector does not support arrays at the moment
|
||||
bdd.itIf(connectorCapabilities.supportsArrays !== false,
|
||||
'coerces primitive array datatypes on update', async () => {
|
||||
const createDate = new Date('2019-02-21T12:00:00').toISOString();
|
||||
const createData = {
|
||||
dateArray: [createDate, createDate],
|
||||
numArray: ['1', '2'],
|
||||
};
|
||||
const updateDate = new Date('2019-04-15T12:00:00').toISOString();
|
||||
const updateData = {
|
||||
dateArray: [updateDate, updateDate],
|
||||
numArray: ['3', '4'],
|
||||
};
|
||||
const created = await numAndDateArrayModel.create(createData);
|
||||
const updated = await numAndDateArrayModel.updateAll({id: created.id}, updateData);
|
||||
const found = await numAndDateArrayModel.findById(created.id);
|
||||
found.dateArray[0].should.deepEqual(new Date(updateDate));
|
||||
found.dateArray[1].should.deepEqual(new Date(updateDate));
|
||||
found.numProp.should.equal(3);
|
||||
found.numArray[0].should.equal(3);
|
||||
found.numArray[1].should.equal(4);
|
||||
});
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
/* global getSchema:false */
|
||||
const should = require('./init.js');
|
||||
|
||||
let db, Model;
|
||||
let db, Model, modelWithDecimalArray, dateArrayModel, numArrayModel;
|
||||
|
||||
class NestedClass {
|
||||
constructor(roleName) {
|
||||
|
@ -32,7 +32,24 @@ describe('datatypes', function() {
|
|||
nestedClass: NestedClass,
|
||||
};
|
||||
Model = db.define('Model', modelTableSchema);
|
||||
db.automigrate(['Model'], done);
|
||||
modelWithDecimalArray = db.define('modelWithDecimalArray', {
|
||||
randomReview: {
|
||||
type: [String],
|
||||
mongodb: {
|
||||
dataType: 'Decimal128',
|
||||
},
|
||||
},
|
||||
});
|
||||
dateArrayModel = db.define('dateArrayModel', {
|
||||
bunchOfDates: [Date],
|
||||
bunchOfOtherDates: {
|
||||
type: [Date],
|
||||
},
|
||||
});
|
||||
numArrayModel = db.define('numArrayModel', {
|
||||
bunchOfNums: [Number],
|
||||
});
|
||||
db.automigrate(['Model', 'modelWithDecimalArray', 'dateArrayModel', 'numArrayModel'], done);
|
||||
});
|
||||
|
||||
it('should resolve top-level "type" property correctly', function() {
|
||||
|
@ -53,25 +70,12 @@ describe('datatypes', function() {
|
|||
Account.definition.properties.item.type.should.not.equal(String);
|
||||
});
|
||||
it('should resolve array prop with connector specific metadata', function() {
|
||||
const model = db.define('test', {
|
||||
randomReview: {
|
||||
type: [String],
|
||||
mongodb: {
|
||||
dataType: 'Decimal128',
|
||||
},
|
||||
},
|
||||
});
|
||||
model.definition.properties.randomReview.type.should.deepEqual(Array(String));
|
||||
model.definition.properties.randomReview.mongodb.should.deepEqual({dataType: 'Decimal128'});
|
||||
const props = modelWithDecimalArray.definition.properties;
|
||||
props.randomReview.type.should.deepEqual(Array(String));
|
||||
props.randomReview.mongodb.should.deepEqual({dataType: 'Decimal128'});
|
||||
});
|
||||
|
||||
it('should coerce array of dates from string', async () => {
|
||||
const dateArrayModel = db.define('dateArrayModel', {
|
||||
bunchOfDates: [Date],
|
||||
bunchOfOtherDates: {
|
||||
type: [Date],
|
||||
},
|
||||
});
|
||||
const dateVal = new Date('2019-02-21T12:00:00').toISOString();
|
||||
const created = await dateArrayModel.create({
|
||||
bunchOfDates: [dateVal,
|
||||
|
@ -88,9 +92,6 @@ describe('datatypes', function() {
|
|||
});
|
||||
|
||||
it('should coerce array of numbers from string', async () => {
|
||||
const numArrayModel = db.define('numArrayModel', {
|
||||
bunchOfNums: [Number],
|
||||
});
|
||||
const dateVal = new Date('2019-02-21T12:00:00').toISOString();
|
||||
const created = await numArrayModel.create({
|
||||
bunchOfNums: ['1',
|
||||
|
|
Loading…
Reference in New Issue