|
|
@@ -4,16 +4,44 @@ describe('config/migrate.js', () => {
|
|
|
jest.resetModules();
|
|
|
});
|
|
|
|
|
|
+ test('throws an error when MIGRATIONS_DIR is not set', () => {
|
|
|
+
|
|
|
+ const initMongooseGlobalSettingsMock = jest.fn();
|
|
|
+
|
|
|
+ // mock for mongoose-utils
|
|
|
+ jest.doMock('@growi/core', () => {
|
|
|
+ return {
|
|
|
+ initMongooseGlobalSettings: initMongooseGlobalSettingsMock,
|
|
|
+ };
|
|
|
+ });
|
|
|
+
|
|
|
+ const requireConfig = () => {
|
|
|
+ require('^/migrate-mongo-config');
|
|
|
+ };
|
|
|
+
|
|
|
+ expect(requireConfig).toThrow('An env var MIGRATIONS_DIR must be set.');
|
|
|
+
|
|
|
+ jest.dontMock('@growi/core');
|
|
|
+
|
|
|
+ expect(initMongooseGlobalSettingsMock).not.toHaveBeenCalled();
|
|
|
+ });
|
|
|
+
|
|
|
/* eslint-disable indent */
|
|
|
describe.each`
|
|
|
- MONGO_URI | expectedUrl | expectedDbName
|
|
|
- ${'mongodb://example.com/growi'} | ${'mongodb://example.com/growi'} | ${'growi'}
|
|
|
- ${'mongodb://user:pass@example.com/growi'} | ${'mongodb://user:pass@example.com/growi'} | ${'growi'}
|
|
|
- ${'mongodb://example.com/growi?replicaSet=mySet'} | ${'mongodb://example.com/growi?replicaSet=mySet'} | ${'growi'}
|
|
|
- `('returns', ({ MONGO_URI, expectedUrl, expectedDbName }) => {
|
|
|
+ MONGO_URI | expectedDbName
|
|
|
+ ${'mongodb://example.com/growi'} | ${'growi'}
|
|
|
+ ${'mongodb://user:pass@example.com/growi'} | ${'growi'}
|
|
|
+ ${'mongodb://example.com/growi?replicaSet=mySet'} | ${'growi'}
|
|
|
+ `('returns', ({ MONGO_URI, expectedDbName }) => {
|
|
|
+
|
|
|
+ beforeEach(async() => {
|
|
|
+ process.env.MIGRATIONS_DIR = 'testdir/migrations';
|
|
|
+ });
|
|
|
+
|
|
|
test(`when 'MONGO_URI' is '${MONGO_URI}`, () => {
|
|
|
|
|
|
const initMongooseGlobalSettingsMock = jest.fn();
|
|
|
+ const mongoOptionsMock = jest.fn();
|
|
|
|
|
|
// mock for mongoose-utils
|
|
|
jest.doMock('@growi/core', () => {
|
|
|
@@ -22,17 +50,20 @@ describe('config/migrate.js', () => {
|
|
|
getMongoUri: () => {
|
|
|
return MONGO_URI;
|
|
|
},
|
|
|
+ mongoOptions: mongoOptionsMock,
|
|
|
};
|
|
|
});
|
|
|
|
|
|
- const { mongoUri, mongodb } = require('^/config/migrate');
|
|
|
+ const { mongodb, migrationsDir, changelogCollectionName } = require('^/migrate-mongo-config');
|
|
|
|
|
|
jest.dontMock('@growi/core');
|
|
|
|
|
|
expect(initMongooseGlobalSettingsMock).toHaveBeenCalledTimes(1);
|
|
|
- expect(mongoUri).toBe(MONGO_URI);
|
|
|
- expect(mongodb.url).toBe(expectedUrl);
|
|
|
+ expect(mongodb.url).toBe(MONGO_URI);
|
|
|
expect(mongodb.databaseName).toBe(expectedDbName);
|
|
|
+ expect(mongodb.options).toBe(mongoOptionsMock);
|
|
|
+ expect(migrationsDir).toBe('testdir/migrations');
|
|
|
+ expect(changelogCollectionName).toBe('migrations');
|
|
|
});
|
|
|
});
|
|
|
/* eslint-enable indent */
|