From b64e47f42ad4318091092916c544bf320716e6db Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Sat, 8 Jul 2017 21:13:47 -0700 Subject: [PATCH] Circle CI (#113) Circle CI --- circle.yml | 24 +++++++ frontend/models/Document.test.js | 3 +- server/.jestconfig.json | 5 +- server/config/database.json | 2 +- ...-collection-documentStructure-migration.js | 14 ++-- server/migrations/20170604052346-add-views.js | 70 ++++++++++--------- server/migrations/20170604052347-add-stars.js | 60 ++++++++-------- server/test/helper.js | 3 +- 8 files changed, 107 insertions(+), 74 deletions(-) create mode 100644 circle.yml diff --git a/circle.yml b/circle.yml new file mode 100644 index 000000000..51020211c --- /dev/null +++ b/circle.yml @@ -0,0 +1,24 @@ +machine: + node: + version: 7.6 + services: + - redis + environment: + ENVIRONMENT: test + PATH: "${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin" + SEQUELIZE_SECRET: F0E5AD933D7F6FD8F4DBB3E038C501C052DC0593C686D21ACB30AE205D2F634B + DATABASE_URL_TEST: postgres://ubuntu@localhost:5432/circle_test + DATABASE_URL: postgres://ubuntu@localhost:5432/circle_test + +dependencies: + override: + - yarn + cache_directories: + - ~/.cache/yarn + +test: + pre: + - sequelize db:migrate --url postgres://ubuntu@localhost:5432/circle_test + override: + - yarn test + - yarn lint diff --git a/frontend/models/Document.test.js b/frontend/models/Document.test.js index e7db05b7d..f84327064 100644 --- a/frontend/models/Document.test.js +++ b/frontend/models/Document.test.js @@ -5,8 +5,7 @@ describe('Document model', () => { test('should initialize with data', () => { const document = new Document({ id: 123, - title: 'Onboarding', - text: 'Some body text' + text: '# Onboarding\nSome body text', }); expect(document.title).toBe('Onboarding'); }); diff --git a/server/.jestconfig.json b/server/.jestconfig.json index 56da3efdc..383aded9b 100644 --- a/server/.jestconfig.json +++ b/server/.jestconfig.json @@ -5,8 +5,7 @@ "/server" ], "setupFiles": [ - "/__mocks__/console.js", - "./server/test/helper.js" + "/__mocks__/console.js" ], "testEnvironment": "node" -} +} \ No newline at end of file diff --git a/server/config/database.json b/server/config/database.json index bff4eeb07..7fdc75998 100644 --- a/server/config/database.json +++ b/server/config/database.json @@ -11,4 +11,4 @@ "use_env_variable": "DATABASE_URL", "dialect": "postgres" } -} +} \ No newline at end of file diff --git a/server/migrations/20170603185012-add-collection-documentStructure-migration.js b/server/migrations/20170603185012-add-collection-documentStructure-migration.js index aa92416d2..671b2e679 100644 --- a/server/migrations/20170603185012-add-collection-documentStructure-migration.js +++ b/server/migrations/20170603185012-add-collection-documentStructure-migration.js @@ -1,14 +1,16 @@ module.exports = { up: (queryInterface, Sequelize) => { - queryInterface.renameTable('atlases', 'collections'); - queryInterface.addColumn('collections', 'documentStructure', { - type: Sequelize.JSONB, - allowNull: true, + queryInterface.renameTable('atlases', 'collections').then(() => { + queryInterface.addColumn('collections', 'documentStructure', { + type: Sequelize.JSONB, + allowNull: true, + }); }); }, down: (queryInterface, _Sequelize) => { - queryInterface.renameTable('collections', 'atlases'); - queryInterface.removeColumn('atlases', 'documentStructure'); + queryInterface.renameTable('collections', 'atlases').then(() => { + queryInterface.removeColumn('atlases', 'documentStructure'); + }); }, }; diff --git a/server/migrations/20170604052346-add-views.js b/server/migrations/20170604052346-add-views.js index cd143c726..cbaea8083 100644 --- a/server/migrations/20170604052346-add-views.js +++ b/server/migrations/20170604052346-add-views.js @@ -1,40 +1,44 @@ module.exports = { up: function(queryInterface, Sequelize) { - queryInterface.createTable('views', { - id: { - type: Sequelize.UUID, - allowNull: false, - primaryKey: true, - }, - documentId: { - type: Sequelize.UUID, - allowNull: false, - }, - userId: { - type: Sequelize.UUID, - allowNull: false, - }, - count: { - type: Sequelize.INTEGER, - allowNull: false, - defaultValue: 1, - }, - createdAt: { - type: Sequelize.DATE, - allowNull: false, - }, - updatedAt: { - type: Sequelize.DATE, - allowNull: false, - }, - }); - queryInterface.addIndex('views', ['documentId', 'userId'], { - indicesType: 'UNIQUE', - }); + queryInterface + .createTable('views', { + id: { + type: Sequelize.UUID, + allowNull: false, + primaryKey: true, + }, + documentId: { + type: Sequelize.UUID, + allowNull: false, + }, + userId: { + type: Sequelize.UUID, + allowNull: false, + }, + count: { + type: Sequelize.INTEGER, + allowNull: false, + defaultValue: 1, + }, + createdAt: { + type: Sequelize.DATE, + allowNull: false, + }, + updatedAt: { + type: Sequelize.DATE, + allowNull: false, + }, + }) + .then(() => { + queryInterface.addIndex('views', ['documentId', 'userId'], { + indicesType: 'UNIQUE', + }); + }); }, down: function(queryInterface, Sequelize) { - queryInterface.removeIndex('views', ['documentId', 'userId']); - queryInterface.dropTable('views'); + queryInterface.removeIndex('views', ['documentId', 'userId']).then(() => { + queryInterface.dropTable('views'); + }); }, }; diff --git a/server/migrations/20170604052347-add-stars.js b/server/migrations/20170604052347-add-stars.js index 78ad77125..1046022d6 100644 --- a/server/migrations/20170604052347-add-stars.js +++ b/server/migrations/20170604052347-add-stars.js @@ -1,35 +1,39 @@ module.exports = { up: function(queryInterface, Sequelize) { - queryInterface.createTable('stars', { - id: { - type: Sequelize.UUID, - allowNull: false, - primaryKey: true, - }, - documentId: { - type: Sequelize.UUID, - allowNull: false, - }, - userId: { - type: Sequelize.UUID, - allowNull: false, - }, - createdAt: { - type: Sequelize.DATE, - allowNull: false, - }, - updatedAt: { - type: Sequelize.DATE, - allowNull: false, - }, - }); - queryInterface.addIndex('stars', ['documentId', 'userId'], { - indicesType: 'UNIQUE', - }); + queryInterface + .createTable('stars', { + id: { + type: Sequelize.UUID, + allowNull: false, + primaryKey: true, + }, + documentId: { + type: Sequelize.UUID, + allowNull: false, + }, + userId: { + type: Sequelize.UUID, + allowNull: false, + }, + createdAt: { + type: Sequelize.DATE, + allowNull: false, + }, + updatedAt: { + type: Sequelize.DATE, + allowNull: false, + }, + }) + .then(() => { + queryInterface.addIndex('stars', ['documentId', 'userId'], { + indicesType: 'UNIQUE', + }); + }); }, down: function(queryInterface, Sequelize) { - queryInterface.removeIndex('stars', ['documentId', 'userId']); - queryInterface.dropTable('stars'); + queryInterface.removeIndex('stars', ['documentId', 'userId']).then(() => { + queryInterface.dropTable('stars'); + }); }, }; diff --git a/server/test/helper.js b/server/test/helper.js index 51171e1e1..05d110c66 100644 --- a/server/test/helper.js +++ b/server/test/helper.js @@ -1,4 +1,5 @@ -require('dotenv').config({ silent: true }); +// @flow +require('../../init'); // test environment variables process.env.DATABASE_URL = process.env.DATABASE_URL_TEST;