|
| 1 | +const expect = require('expect.js'); |
| 2 | +const Support = require(__dirname + '/../../../support'); |
| 3 | +const helpers = require(__dirname + '/../../../support/helpers'); |
| 4 | +const gulp = require('gulp'); |
| 5 | +const _ = require('lodash'); |
| 6 | + |
| 7 | +[ |
| 8 | + 'db:seed:undo --seed seedPerson.js', |
| 9 | + 'db:seed:undo' |
| 10 | +].forEach(flag => { |
| 11 | + const prepare = function (callback, options) { |
| 12 | + const _flag = options.flag || flag; |
| 13 | + const config = _.assign({}, helpers.getTestConfig(), options.config || {}); |
| 14 | + |
| 15 | + const pipeline = gulp |
| 16 | + .src(Support.resolveSupportPath('tmp')) |
| 17 | + .pipe(helpers.clearDirectory()) |
| 18 | + .pipe(helpers.runCli('init')) |
| 19 | + .pipe(helpers.copyMigration('createPerson.js')); |
| 20 | + |
| 21 | + if ( options.copySeeds ) { |
| 22 | + pipeline.pipe(helpers.copySeeder('seedPerson.js')) |
| 23 | + .pipe(helpers.copySeeder('seedPerson2.js')); |
| 24 | + } |
| 25 | + |
| 26 | + pipeline.pipe(helpers.overwriteFile(JSON.stringify(config), |
| 27 | + 'config/config.json')) |
| 28 | + .pipe(helpers.runCli('db:migrate')) |
| 29 | + .pipe(helpers.runCli(_flag, { pipeStdout: true })) |
| 30 | + .pipe(helpers.teardown(callback)); |
| 31 | + }; |
| 32 | + |
| 33 | + describe(Support.getTestDialectTeaser(flag), () => { |
| 34 | + it('stops execution if no seeders have been found', done => { |
| 35 | + prepare((err, output) => { |
| 36 | + expect(err).to.equal(null); |
| 37 | + expect(output).to.contain('No seeders found.'); |
| 38 | + done(); |
| 39 | + }, {copySeeds: false}); |
| 40 | + }); |
| 41 | + |
| 42 | + it('is correctly undo seed if they have been done already', function (done) { |
| 43 | + const self = this; |
| 44 | + |
| 45 | + prepare(() => { |
| 46 | + helpers.countTable(self.sequelize, 'Person', res => { |
| 47 | + expect(res).to.have.length(1); |
| 48 | + expect(res[0].count).to.eql(2); |
| 49 | + |
| 50 | + gulp |
| 51 | + .src(Support.resolveSupportPath('tmp')) |
| 52 | + .pipe(helpers.runCli(flag, { pipeStdout: true })) |
| 53 | + .pipe(helpers.teardown(() => { |
| 54 | + helpers.countTable(self.sequelize, 'Person', res => { |
| 55 | + expect(res).to.have.length(1); |
| 56 | + expect(res[0].count).to.eql(0); |
| 57 | + done(); |
| 58 | + }); |
| 59 | + })); |
| 60 | + }); |
| 61 | + }, {flag: 'db:seed:all', copySeeds: true}); |
| 62 | + }); |
| 63 | + |
| 64 | + it('is correctly undo seed when storage is none', function (done) { |
| 65 | + const self = this; |
| 66 | + |
| 67 | + prepare(() => { |
| 68 | + helpers.countTable(self.sequelize, 'Person', res => { |
| 69 | + expect(res).to.have.length(1); |
| 70 | + expect(res[0].count).to.eql(2); |
| 71 | + |
| 72 | + gulp |
| 73 | + .src(Support.resolveSupportPath('tmp')) |
| 74 | + .pipe(helpers.runCli(flag, { pipeStdout: true })) |
| 75 | + .pipe(helpers.teardown(() => { |
| 76 | + helpers.countTable(self.sequelize, 'Person', res => { |
| 77 | + expect(res).to.have.length(1); |
| 78 | + expect(res[0].count).to.eql(0); |
| 79 | + done(); |
| 80 | + }); |
| 81 | + })); |
| 82 | + }); |
| 83 | + }, { |
| 84 | + flag: 'db:seed:all', |
| 85 | + copySeeds: true, |
| 86 | + config: { seederStorage: 'none' } |
| 87 | + }); |
| 88 | + }); |
| 89 | + }); |
| 90 | +}); |
0 commit comments