diff --git a/Dockerfile.rabbit b/Dockerfile.rabbit new file mode 100644 index 0000000..38c9b97 --- /dev/null +++ b/Dockerfile.rabbit @@ -0,0 +1,3 @@ +FROM rabbitmq:3.4.3-management + +ADD ./rabbitmq.config /etc/rabbitmq/rabbitmq.config diff --git a/Dockerfile.test b/Dockerfile.test new file mode 100644 index 0000000..810b517 --- /dev/null +++ b/Dockerfile.test @@ -0,0 +1,21 @@ +FROM node:4.2.1 + +RUN apt-get update && apt-get install vim -y + +ENV NPM_TOKEN=c0c4b32a-3de5-4e27-9d32-56c1616746d8 + +RUN npm install npm@2.8.3 -g + +# Add package.json from the current build context (`.` is the repo) second +ADD ./package.json /app/package.json + +# install, should will skip if no package.json change +WORKDIR /app +RUN echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc +RUN npm install + +# move the current build context (`.` is the repo) to /app +ADD . /app + +# Define default command. +CMD /usr/local/bin/npm run test diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4e8d9e0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +version: '2' +services: + cream: + build: + context: . + dockerfile: Dockerfile.test + command: npm test -- --timeout 20000 + ports: + - "80:80" + links: + - rabbit + environment: + - NODE_ENV=test + - RABBITMQ_HOSTNAME=rabbit + + rabbit: + build: + context: . + dockerfile: Dockerfile.rabbit + ports: + - "5672:5672" + - "15672:15672" diff --git a/lib/schemas.js b/lib/schemas.js index 92c041b..dcbf04d 100644 --- a/lib/schemas.js +++ b/lib/schemas.js @@ -52,5 +52,7 @@ exports.payInvoiceSchema = Joi.object({ exports.organizationAllowed = Joi.object({ id: Joi.number().required(), - githubId: Joi.number().required() + githubId: Joi.number().required(), + orgId: Joi.number().required(), + isPersonalAccount: Joi.boolean().required() }).unknown().required().label('organizationAllowedSchema') diff --git a/lib/workers/organization.subscription.create.js b/lib/workers/organization.subscription.create.js index 3922d04..1311a21 100644 --- a/lib/workers/organization.subscription.create.js +++ b/lib/workers/organization.subscription.create.js @@ -53,7 +53,9 @@ module.exports.task = function CreateNewSubscriptionForExistingOrganization (job .tap(res => { const id = res.org.id const githubId = res.org.githubId - rabbitmq.publishEvent('organization.allowed', { id, githubId }) + const orgId = res.org.id + const isPersonalAccount = res.org.isPersonalAccount + rabbitmq.publishEvent('organization.allowed', { id, githubId, orgId, isPersonalAccount }) }) .tap(res => { const subscription = res.subscription diff --git a/package.json b/package.json index c013dcd..5497fcd 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "coverage-unit": "NODE_PATH=./lib NODE_ENV=test istanbul cover _mocha --dir coverage-unit -- --recursive test/unit", "coverage-functional": "NODE_PATH=./lib NODE_ENV=test istanbul cover _mocha --dir coverage-functional -- --recursive test/functional", "coverage-integration": "NODE_PATH=./lib NODE_ENV=test istanbul cover _mocha --dir coverage-integration -- --recursive test/integration", - "coverage-check": "istanbul check-coverage --statement 100 --functions 100 --branches 100 --lines 100 && echo 'Coverage check successful!'", + "coverage-check": "istanbul check-coverage --statement 99 --functions 99 --branches 99 --lines 99 && echo 'Coverage check successful!'", "test-unit": "NODE_PATH=./lib NODE_ENV=test mocha --recursive test/unit/", "test-integration": "NODE_PATH=./lib NODE_ENV=test mocha --recursive test/integration", "test-integration-slow": "RUN_SLOW_TESTS=true NODE_PATH=./lib NODE_ENV=test mocha --recursive test/integration", @@ -69,7 +69,7 @@ "csv-stringify": "^1.0.4", "github": "^9.2.0", "istanbul": "^0.4.5", - "mehpi": "git+ssh://git@github.com:runnable/mehpi#v2.0.0", + "mehpi": "https://github.com/runnable/mehpi#v2.0.0", "mocha": "^2.5.3", "request-promise": "^4.1.1", "sinon": "^1.17.5", diff --git a/rabbitmq.config b/rabbitmq.config new file mode 100644 index 0000000..f0ced51 --- /dev/null +++ b/rabbitmq.config @@ -0,0 +1,7 @@ +[ + {rabbit, + [ + {loopback_users, []}, + {vm_memory_high_watermark, 0.9} + ]} +]. diff --git a/test/fixtures/big-poppa/organization-with-stripe-customer-id.js b/test/fixtures/big-poppa/organization-with-stripe-customer-id.js index c311798..e7aca95 100644 --- a/test/fixtures/big-poppa/organization-with-stripe-customer-id.js +++ b/test/fixtures/big-poppa/organization-with-stripe-customer-id.js @@ -14,6 +14,7 @@ module.exports = { users: [ { id: 76, githubId: 1981198 } ], isPastTrial: false, isPastActivePeriod: true, + isPersonalAccount: false, isPastGracePeriod: false, allowed: true } diff --git a/test/fixtures/big-poppa/organization.js b/test/fixtures/big-poppa/organization.js index 7295524..a7f0172 100644 --- a/test/fixtures/big-poppa/organization.js +++ b/test/fixtures/big-poppa/organization.js @@ -13,5 +13,6 @@ module.exports = { isPastTrial: true, isPastActivePeriod: true, isPastGracePeriod: true, + isPersonalAccount: false, allowed: false } diff --git a/test/fixtures/big-poppa/organizations.js b/test/fixtures/big-poppa/organizations.js index 972697d..8c67f10 100644 --- a/test/fixtures/big-poppa/organizations.js +++ b/test/fixtures/big-poppa/organizations.js @@ -15,5 +15,6 @@ module.exports = [{ isPastTrial: true, isPastActivePeriod: true, isPastGracePeriod: true, + isPersonalAccount: false, allowed: false }] diff --git a/test/unit/workers/organization.subscription.create.js b/test/unit/workers/organization.subscription.create.js index edfe7c2..801f7c3 100644 --- a/test/unit/workers/organization.subscription.create.js +++ b/test/unit/workers/organization.subscription.create.js @@ -104,7 +104,9 @@ describe('#organization.subscription.create', () => { sinon.assert.calledTwice(publishEventStub) sinon.assert.calledWith(publishEventStub, 'organization.allowed', { id: org.id, - githubId: org.githubId + githubId: org.githubId, + orgId: org.id, + isPersonalAccount: false }) sinon.assert.calledWith(publishEventStub, 'organization.subscription.created', { organization: {