Skip to content

Commit

Permalink
MOD improve test on migration
Browse files Browse the repository at this point in the history
  • Loading branch information
stombre committed Nov 7, 2020
1 parent d46ca08 commit 0cc7a49
Showing 1 changed file with 43 additions and 8 deletions.
51 changes: 43 additions & 8 deletions spec/common/extra/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ const TIME_V2 = 1601825250;
const TIME_V3 = 1611825250;

module.exports = (TestContext) => {
const testContext = TestContext.getInvoices();
const testContext = new TestContext();

describe('Migration', () => {
const { Schema, } = testContext.ilorm;
after(async () => {
await testContext.deleteSource('users');

return testContext.finalCleanUp();
});

const { Schema, newModel, } = testContext.ilorm;

// Always most recent version;
const userSchema = new Schema({
Expand Down Expand Up @@ -45,20 +51,49 @@ module.exports = (TestContext) => {
});

it('API version should work', () => {
userSchema.version(TIME_V2, {
id: Schema.string(),
name: Schema.string(),
age: Schema.string(),
})
userSchema
.version(TIME_V2, {
id: Schema.string(),
name: Schema.string(),
age: Schema.string(),
})
.version(TIME_V1, {
id: Schema.string(),
name: Schema.string(),
})
.up(async (UserModel) => {
const user = new UserModel();

user.id = '12345';
user.name = 'Guillaume Daix';

await user.save();
});
});

it('Should apply past schema', () => {
let UserModel;

it('Should build db with the most recent schema', async () => {
UserModel = newModel({
connector: new testContext.Connector({
sourceName: 'users',
}),
schema: userSchema,
});

// Will apply migration in order;
await UserModel.applyMigration();

// The migration TIME_V1 insert a user on an old schema, in theory, still in the db;
const user = await UserModel.query().findOne();

expect(user.id).to.be.equals('12345');
expect(user.firstName).to.be.equals('Guillaume');
expect(user.lastName).to.be.equals('Daix');
});

it('Should rollback on past schema', () => {});

it('Should re-up on last schema', () => {});
});
};

0 comments on commit 0cc7a49

Please sign in to comment.