migrate.test.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. describe('config/migrate.js', () => {
  2. beforeEach(async(done) => {
  3. jest.resetModules();
  4. done();
  5. });
  6. /* eslint-disable indent */
  7. describe.each`
  8. MONGO_URI | expectedUrl | expectedDbName
  9. ${'mongodb://example.com/growi'} | ${'mongodb://example.com/growi'} | ${'growi'}
  10. ${'mongodb://user:pass@example.com/growi'} | ${'mongodb://user:pass@example.com/growi'} | ${'growi'}
  11. ${'mongodb://example.com/growi?replicaSet=mySet'} | ${'mongodb://example.com/growi?replicaSet=mySet'} | ${'growi'}
  12. `('returns', ({ MONGO_URI, expectedUrl, expectedDbName }) => {
  13. test(`when 'MONGO_URI' is '${MONGO_URI}`, () => {
  14. // mock for mongoose-utils
  15. jest.doMock('@commons/util/mongoose-utils', () => {
  16. return {
  17. getMongoUri: () => {
  18. return MONGO_URI;
  19. },
  20. };
  21. });
  22. const { mongoUri, mongodb } = require('@root/config/migrate');
  23. jest.dontMock('@commons/util/mongoose-utils');
  24. expect(mongoUri).toBe(MONGO_URI);
  25. expect(mongodb.url).toBe(expectedUrl);
  26. expect(mongodb.databaseName).toBe(expectedDbName);
  27. });
  28. });
  29. /* eslint-enable indent */
  30. });