diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0d145cbc9..000000000 --- a/.travis.yml +++ /dev/null @@ -1,31 +0,0 @@ -# We want to avoid unnecessary test runs, because they load the API, so: -# - we run tests for all changes in PRs -# - we run deploys for all version-tagged commits -# - we don't want to do anything for any other cases -# Travis has a bunch of filtering that's supposed to cover this sort of thing, but -# it doesn't quite work. - -sudo: required -addons: - chrome: stable - -language: node_js -matrix: - include: - - node_js: - - '8' -before_install: -- npm -g install npm@4 -script: -# Skip tests entirely, unless it's a pull request -# If we end up deploying, a deploy runs the tests anyway -- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then npm run ci; fi' - -notifications: - email: false - webhooks: - urls: - - https://webhooks.gitter.im/e/8b150eaf525c280ec2ac - on_success: change - on_failure: always - on_start: never diff --git a/README.md b/README.md index 8ffa7b2ee..c2db73d0e 100644 --- a/README.md +++ b/README.md @@ -76,37 +76,43 @@ If you're having any problem, please [raise an issue](https://github.com/resin-i Tests ----- -In order to run the Resin SDK test suite, set the following environment variables from an account that exists and doesn't have a billing account code: -**WARNING: This will delete all applications and public keys of the test user** +Run the test suite by doing: + +```sh +$ npm test +``` -- `RESINTEST_EMAIL`: The main account email -- `RESINTEST_PASSWORD`: The main account password -- `RESINTEST_USERNAME`: The main account username. +### API Url -You also have to provide the following environment variables from an account that doesn't yet exists: +You can, optionally, set the `RESINTEST_API_URL` environment variable in order to run the tests using a different API backend (eg: `https://api.resinstaging.io`). -- `RESINTEST_REGISTER_EMAIL`: The email of the account to register. -- `RESINTEST_REGISTER_PASSWORD`: The password of the account to register. -- `RESINTEST_REGISTER_USERNAME`: The username of the account to register. +### Billing -In order to test the billing methods for a paid account, you also have to configure the following environment variables: +In order to test the billing methods for a paid account, you have to configure the following environment variables: - `RESINTEST_PAID_EMAIL`: The email of the paid account. - `RESINTEST_PAID_PASSWORD`: The password of the account. -*Note: The paid user's `account billing code` should be set to `testdev` so that it's tested against the test plan.* +*Note: The paid user's `account billing code` should be set to `testdev` so that it's tested against the proper plan.* -You can also, optionally, set the `RESINTEST_API_URL` environment variable in order to run the tests using a different API backend (eg: `https://api.resinstaging.io`). +### Avoiding rate limiting errors + +While developing you might end up in a situation that the API returns rate limiting errors. +That's probably caused by the new user signups that each run of the test suit does. +You can avoid those errors to some extend by specifying a pre-existing **empty** user account to run the suit against. +In order to do so, set the following environment variables for an account that exists and doesn't have a billing account code: +**WARNING: This will delete all applications and public keys of the test user** + +- `RESINTEST_EMAIL`: The test account email +- `RESINTEST_PASSWORD`: The test account password +- `RESINTEST_USERNAME`: The test account username. + +### Persisting ENV configuration You can persist these settings by putting them all into a `.env` file in the root of this repo, in [dotenv](https://www.npmjs.com/package/dotenv) format (`KEY=VALUE\n`). This will be automatically detected and used in the tests. Make sure you don't accidentally commit this file (`.env` by default is gitignored, so hopefully this should be difficult). -Run the test suite by doing: - -```sh -$ npm test -``` Contribute ---------- @@ -114,10 +120,10 @@ Contribute - Issue Tracker: [github.com/resin-io/resin-sdk/issues](https://github.com/resin-io/resin-sdk/issues) - Source Code: [github.com/resin-io/resin-sdk](https://github.com/resin-io/resin-sdk) -Before submitting a PR, please make sure that you include tests, and that [coffeelint](http://www.coffeelint.org/) runs without any warning: +Before submitting a PR, please make sure that you include tests, and that the linter runs without any warning: ```sh -$ gulp lint +$ npm run lint ``` License diff --git a/appveyor.yml b/appveyor.yml index 6ada37980..af3c6a423 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -15,10 +15,9 @@ matrix: environment: matrix: - nodejs_version: 6 - RESINTEST_EMAIL: 'test3+juan@resin.io' - RESINTEST_USERNAME: 'test3_juan' - RESINTEST_REGISTER_EMAIL: 'test3+register+juan@resin.io' - RESINTEST_REGISTER_USERNAME: 'test3_register_juan' + RESINTEST_PAID_EMAIL: 'test+paid+thodoris@resin.io' + RESINTEST_PAID_PASSWORD: + secure: zqKu7kmQ2b53eRh4lPwKW1ht/Va/ykIuDwdkkT5cwgc= install: - ps: Install-Product node $env:nodejs_version x64 diff --git a/karma.conf.coffee b/karma.conf.coffee index 76193646e..5593b56fe 100644 --- a/karma.conf.coffee +++ b/karma.conf.coffee @@ -8,7 +8,13 @@ module.exports = (config) -> loadEnv() karmaConfig.plugins.push(require('karma-chrome-launcher')) - karmaConfig.browsers = ['ChromeHeadless'] + karmaConfig.browsers = ['ChromeHeadlessCustom'] + karmaConfig.customLaunchers = + ChromeHeadlessCustom: + base: 'ChromeHeadless' + flags: [ + '--no-sandbox' + ] karmaConfig.logLevel = config.LOG_INFO karmaConfig.sauceLabs = @@ -41,9 +47,6 @@ module.exports = (config) -> 'RESINTEST_USERNAME' 'RESINTEST_PAID_EMAIL' 'RESINTEST_PAID_PASSWORD' - 'RESINTEST_REGISTER_EMAIL' - 'RESINTEST_REGISTER_PASSWORD' - 'RESINTEST_REGISTER_USERNAME' ] config.set(karmaConfig) diff --git a/tests/integration/models/image.spec.coffee b/tests/integration/models/image.spec.coffee index b8c25a338..4b32b9fe3 100644 --- a/tests/integration/models/image.spec.coffee +++ b/tests/integration/models/image.spec.coffee @@ -1,7 +1,7 @@ m = require('mochainon') _ = require('lodash') -{ resin, credentials, givenLoggedInUser, givenMulticontainerApplication } = require('../setup') +{ resin, givenLoggedInUser, givenMulticontainerApplication } = require('../setup') describe 'Image Model', -> diff --git a/tests/integration/models/service.spec.coffee b/tests/integration/models/service.spec.coffee index 7f4e450e1..92a178294 100644 --- a/tests/integration/models/service.spec.coffee +++ b/tests/integration/models/service.spec.coffee @@ -1,7 +1,7 @@ m = require('mochainon') _ = require('lodash') -{ resin, credentials, givenLoggedInUser, givenMulticontainerApplication } = require('../setup') +{ resin, givenLoggedInUser, givenMulticontainerApplication } = require('../setup') describe 'Service Model', -> diff --git a/tests/integration/resin.spec.coffee b/tests/integration/resin.spec.coffee index 3cfe2048a..928bbdf60 100644 --- a/tests/integration/resin.spec.coffee +++ b/tests/integration/resin.spec.coffee @@ -1,6 +1,6 @@ m = require('mochainon') -{ resin, getSdk, sdkOpts, credentials, givenLoggedInUser } = require('./setup') +{ resin, getSdk, sdkOpts, givenLoggedInUser } = require('./setup') describe 'Resin SDK', -> diff --git a/tests/integration/setup.coffee b/tests/integration/setup.coffee index 1210cb022..77c5031dd 100644 --- a/tests/integration/setup.coffee +++ b/tests/integration/setup.coffee @@ -5,6 +5,7 @@ _ = require('lodash') chai.use(require('chai-samsam')) exports.IS_BROWSER = IS_BROWSER = window? +exports.credentials = {} if IS_BROWSER require('js-polyfills/es6') @@ -30,38 +31,50 @@ _.assign opts, isBrowser: IS_BROWSER, retries: 3 -buildCredentials = -> - if not env - throw new Error('Missing environment object?!') +exports.getSdk = getSdk +exports.sdkOpts = opts +exports.resin = resin = getSdk(opts) + +shouldDeleteTestUser = false - credentials = - email: env.RESINTEST_EMAIL - password: env.RESINTEST_PASSWORD - username: env.RESINTEST_USERNAME +getCredentials = _.once Promise.method -> + username = "sdk_tests_#{Date.now()}" + register_username = "#{username}_reg" + + getUserCredentials = (username) -> + username: username + email: "#{username}@resin.io" + password: "#{username}_!@#" + + tmpEnv = env || {} + envTestUserCredentials = + username: tmpEnv.RESINTEST_USERNAME + email: tmpEnv.RESINTEST_EMAIL + password: tmpEnv.RESINTEST_PASSWORD + + envPaidUserCredentials = paid: - email: env.RESINTEST_PAID_EMAIL - password: env.RESINTEST_PAID_PASSWORD - register: - email: env.RESINTEST_REGISTER_EMAIL - password: env.RESINTEST_REGISTER_PASSWORD - username: env.RESINTEST_REGISTER_USERNAME - - if not _.every [ - credentials.email? - credentials.password? - credentials.username? - credentials.register.email? - credentials.register.password? - credentials.register.username? - ] - throw new Error('Missing environment credentials') - - return credentials + email: tmpEnv.RESINTEST_PAID_EMAIL + password: tmpEnv.RESINTEST_PAID_PASSWORD -exports.getSdk = getSdk + credentials = _.assign({}, + getUserCredentials(username), + envPaidUserCredentials, + register: getUserCredentials(register_username) + ) -exports.sdkOpts = opts -exports.resin = resin = getSdk(opts) + if _.every(envTestUserCredentials) + console.log('Using ENV test user credentials') + _.assign(credentials, envTestUserCredentials) + return credentials + + resin.auth.register + email: credentials.email + password: credentials.password + .tap -> shouldDeleteTestUser = true + .return(credentials) + .tapCatch -> + console.error('Failed to autogenerate test credentials!') exports.resetUser = -> return resin.auth.isLoggedIn().then (isLoggedIn) -> @@ -82,8 +95,6 @@ exports.resetUser = -> .catchReturn() ] -exports.credentials = buildCredentials() - exports.givenLoggedInUserWithApiKey = -> beforeEach -> resin.auth.login @@ -325,3 +336,31 @@ exports.givenMulticontainerApplication = -> @oldWebInstall = oldWebInstall @newWebInstall = newWebInstall @newDbInstall = newDbInstall + +before -> + console.log('************ setup ************') + console.log("API Url: #{opts.apiUrl}") + getCredentials() + .then (result) -> + # use assign, since this runs asynchronously, after + # each test has imported the credentials object + _.assign(exports.credentials, result) + .finally -> console.log() + +after -> + console.log('********** teardown **********') + if !shouldDeleteTestUser + return + + resin.auth.login + email: exports.credentials.email + password: exports.credentials.password + .then(resin.auth.getUserId) + .then (userId) -> + return resin.request.send + method: 'DELETE' + url: "/v2/user(#{userId})" + baseUrl: exports.sdkOpts.apiUrl + .then -> console.log('Deleted autogenerated test user') + .then(resin.auth.logout) + .catch(message: 'Request error: Unauthorized', ->)