Skip to content

Commit

Permalink
test: add tests for 'FindOrCreate'
Browse files Browse the repository at this point in the history
  • Loading branch information
sonirico committed Jun 6, 2020
1 parent edbba08 commit 8af3399
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions types/test/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MyModel extends Model {
}
}

class OtherModel extends Model {}
class OtherModel extends Model { }

const assoc: Association = MyModel.associations.other;

Expand Down Expand Up @@ -46,7 +46,7 @@ MyModel.build({ int: 10 }, { include: OtherModel });

MyModel.bulkCreate([{ int: 10 }], { include: OtherModel });

MyModel.update({}, { where: { foo: 'bar' }, paranoid: false});
MyModel.update({}, { where: { foo: 'bar' }, paranoid: false });

const sequelize = new Sequelize('mysql://user:user@localhost:3306/mydb');

Expand All @@ -71,7 +71,7 @@ MyModel.init({
sequelize,
tableName: 'my_model',
getterMethods: {
multiply: function() {
multiply: function () {
return this.num * 2;
}
}
Expand All @@ -80,7 +80,7 @@ MyModel.init({
/**
* Tests for findCreateFind() type.
*/
class UserModel extends Model {}
class UserModel extends Model { }

UserModel.init({
username: { type: DataTypes.STRING, allowNull: false },
Expand All @@ -99,29 +99,35 @@ UserModel.findCreateFind({
})

/**
* Test for primaryKeyAttributes.
* Tests for findOrCreate() signature.
*/
class TestModel extends Model {};
TestModel.primaryKeyAttributes;

UserModel.findOrCreate({
fields: ['username'],
where: {
username: "jane.doe",
},
defaults: { username: 'jane.doe' }
})

/**
* Test for joinTableAttributes on BelongsToManyGetAssociationsMixin
*/
class SomeModel extends Model {
public getOthers!: BelongsToManyGetAssociationsMixin<OtherModel>
public getOthers!: BelongsToManyGetAssociationsMixin<OtherModel>
}

const someInstance = new SomeModel()
someInstance.getOthers({
joinTableAttributes: { include: [ 'id' ] }
joinTableAttributes: { include: ['id'] }
})

/**
/**
* Test for through options in creating a BelongsToMany association
*/
class Film extends Model {}
class Film extends Model { }

class Actor extends Model {}
class Actor extends Model { }

Film.belongsToMany(Actor, {
through: {
Expand All @@ -135,4 +141,4 @@ Actor.belongsToMany(Film, {
model: 'FilmActors',
paranoid: true
}
})
})

0 comments on commit 8af3399

Please sign in to comment.