Skip to content

Commit

Permalink
make new test work with mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
koskimas committed Nov 9, 2021
1 parent 139c594 commit 4c80295
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 37 deletions.
34 changes: 0 additions & 34 deletions tests/integration/insertGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,40 +545,6 @@ module.exports = (session) => {
});
});

it('should work with a model class that has undefined values as defaults for each column and relation', async () => {
class TestModel extends Model {
id;
model1Id;
model1Prop1;
model1Prop2;
model1Relation1;

static tableName = 'Model1';
static relationMappings = {
model1Relation1: {
relation: TestModel.BelongsToOneRelation,
modelClass: TestModel,
join: {
from: 'Model1.model1Id',
to: 'Model1.id',
},
},
};
}

const result = await TestModel.query(session.knex).insertGraph({
model1Prop1: 'foo',
model1Relation1: {
model1Prop2: 100,
},
});

expect(result.id).to.be.a('number');
expect(result.model1Prop1).to.equal('foo');
expect(result.model1Relation1).to.be.a(TestModel);
expect(result.model1Relation1.model1Prop2).to.equal(100);
});

if (utils.isPostgres(session.knex)) {
it('query building methods should be applied to the root models', () => {
return Model1.query()
Expand Down
25 changes: 22 additions & 3 deletions tests/integration/misc/defaultModelFieldValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ module.exports = (session) => {
.createTable('pet', (table) => {
table.increments('id').primary();
table.string('name');
table.integer('ownerId').references('person.id').onDelete('cascade');
table.integer('ownerId').unsigned().references('person.id').onDelete('cascade');
})
.createTable('toy', (table) => {
table.increments('id').primary();
table.string('toyName');
table.float('price');
})
.createTable('petToy', (table) => {
table.integer('petId').references('pet.id').notNullable().onDelete('cascade');
table.integer('toyId').references('toy.id').notNullable().onDelete('cascade');
table.integer('petId').unsigned().references('pet.id').notNullable().onDelete('cascade');
table.integer('toyId').unsigned().references('toy.id').notNullable().onDelete('cascade');
});
});

Expand Down Expand Up @@ -150,6 +150,25 @@ module.exports = (session) => {
},
],
});

const resultFromDb = await Person.query(knex)
.findById(result.id)
.withGraphFetched({
pets: {
toys: true,
},
});

expect(resultFromDb).to.containSubset({
firstName: 'Arnold',
pets: [
{ name: 'Catto', owner: undefined, toys: [] },
{
name: 'Doggo',
toys: [{ toyName: 'Bone' }],
},
],
});
});

it('withGraphFetched', async () => {
Expand Down

0 comments on commit 4c80295

Please sign in to comment.