Skip to content

Commit

Permalink
Merge pull request #233 from recurly/required-field-tests
Browse files Browse the repository at this point in the history
Required field tests
  • Loading branch information
snodgrass23 committed Feb 11, 2016
2 parents 8d1db92 + 7af73cd commit c2a7a19
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cache:
directories:
- $HOME/travis-phantomjs
script:
- make test
- make test-sauce
addons:
artifacts:
paths:
Expand Down
15 changes: 2 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,8 @@ build/test.js: $(SRC) $(TESTS)
test: build build/test.js
@$(KARMA) start karma.conf.js

test-sauce:

# test: test-phantomjs

# test-phantomjs: build build/test.js
# @$(T) phantomjs

# test-browser: build build/test.js
# @$(T) browser

# test-sauce: BROWSER ?= ie:9
# test-sauce: build build/test.js
# @$(T) saucelabs -b $(BROWSER)
test-sauce: build build/test.js
@$(KARMA) start karma.sauce.conf.js

node_modules: package.json
@npm install --silent
Expand Down
132 changes: 35 additions & 97 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,101 +1,39 @@
module.exports = function (config) {
var sauceBrowsers = {
sl_chrome: {
base: 'SauceLabs',
browserName: 'chrome',
platform: 'Windows 10'
},

sl_firefox: {
base: 'SauceLabs',
browserName: 'firefox',
platform: 'Windows 10'
},

sl_safari: {
base: 'SauceLabs',
browserName: 'safari',
platform: 'OS X 10.11'
},

sl_ie_10: {
base: 'SauceLabs',
browserName: 'internet explorer',
version: '10'
},
sl_ie_11: {
base: 'SauceLabs',
browserName: 'internet explorer',
platform: 'Windows 10',
version: '11'
},

sl_opera: {
base: 'SauceLabs',
browserName: 'opera'
},

sl_ios_8_4: {
base: 'SauceLabs',
browserName: 'iphone',
version: '8.4'
},
sl_ios_9_0: {
base: 'SauceLabs',
browserName: 'iphone',
version: '9.0'
},
sl_ios_9_1: {
base: 'SauceLabs',
browserName: 'iphone',
version: '9.1'
},
sl_ios_9_2: {
base: 'SauceLabs',
browserName: 'iphone',
version: '9.2'
},

sl_android_5_1: {
base: 'SauceLabs',
browserName: 'android',
version: '5.1'
}
};
var staticConfig = {
basePath: '',
frameworks: ['mocha', 'fixture', 'sinon', 'phantomjs-shim', 'source-map-support'],
files: [
'build/recurly.js',
'build/test.js',
{ pattern: 'test/support/fixtures/*' },
],
proxies: { '/api': 'http://localhost:9877' },
preprocessors: {
'test/support/fixtures/*.html': ['html2js'],
'test/support/fixtures/*.json': ['json_fixtures']
},
jsonFixturesPreprocessor: {
variableName: '__json__'
},
reporters: ['mocha'],
port: 9876,
colors: true,
autoWatch: true,
browsers: ['PhantomJS'],
singleRun: true,
concurrency: Infinity,
browserDisconnectTimeout: 300000, // 5 minutes
browserNoActivityTimeout: 300000,
captureTimeout: 300000
};

config.set({
basePath: '',
frameworks: ['mocha', 'fixture', 'sinon', 'phantomjs-shim', 'source-map-support'],
files: [
'build/recurly.js',
'build/test.js',
{ pattern: 'test/support/fixtures/*' },
],
proxies: { '/api': 'http://localhost:9877' },
preprocessors: {
'test/support/fixtures/*.html': ['html2js'],
'test/support/fixtures/*.json': ['json_fixtures']
},
jsonFixturesPreprocessor: {
variableName: '__json__'
},
reporters: ['mocha', 'saucelabs'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['PhantomJS'].concat(Object.keys(sauceBrowsers)),
singleRun: true,
concurrency: Infinity,
sauceLabs: {
testName: 'Recurly.js tests',
recordVideo: true
},
customLaunchers: sauceBrowsers,
browserDisconnectTimeout: 300000, // 5 minutes
browserNoActivityTimeout: 300000,
captureTimeout: 300000
});
var runner = function (config) {
config.set(Object.assign({}, staticConfig, {
logLevel: config.LOG_INFO
}));
};

var server = require('./test/server');

runner.staticConfig = staticConfig;

module.exports = runner;
79 changes: 79 additions & 0 deletions karma.sauce.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
var staticConfig = require('./karma.conf').staticConfig;
var sauceBrowsers = {
sl_chrome: {
base: 'SauceLabs',
browserName: 'chrome',
platform: 'Windows 10'
},

sl_firefox: {
base: 'SauceLabs',
browserName: 'firefox',
platform: 'Windows 10'
},

sl_safari: {
base: 'SauceLabs',
browserName: 'safari',
platform: 'OS X 10.11'
},

sl_ie_10: {
base: 'SauceLabs',
browserName: 'internet explorer',
version: '10'
},
sl_ie_11: {
base: 'SauceLabs',
browserName: 'internet explorer',
platform: 'Windows 10',
version: '11'
},

sl_opera: {
base: 'SauceLabs',
browserName: 'opera'
},

sl_ios_8_4: {
base: 'SauceLabs',
browserName: 'iphone',
version: '8.4'
},
sl_ios_9_0: {
base: 'SauceLabs',
browserName: 'iphone',
version: '9.0'
},
sl_ios_9_1: {
base: 'SauceLabs',
browserName: 'iphone',
version: '9.1'
},
sl_ios_9_2: {
base: 'SauceLabs',
browserName: 'iphone',
version: '9.2'
},

sl_android_5_1: {
base: 'SauceLabs',
browserName: 'android',
version: '5.1'
}
};

module.exports = function (config) {
config.set(Object.assign({}, staticConfig, {
reporters: ['mocha', 'saucelabs'],
logLevel: config.LOG_INFO,
browsers: ['PhantomJS'].concat(Object.keys(sauceBrowsers)),
sauceLabs: {
testName: 'Recurly.js tests',
recordVideo: true
},
customLaunchers: sauceBrowsers,
}));
};

var server = require('./test/server');
50 changes: 50 additions & 0 deletions test/token.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,56 @@ apiTest(requestMethod => {
});
});

describe('when cvv is specifically required', function () {
beforeEach(function (done) {
this.recurly = initRecurly({
cors: requestMethod === 'cors',
required: ['cvv']
});
this.recurly.ready(done);
});

describe('when cvv is blank', function () {
it('produces a validation error', function (done) {
const example = merge(clone(valid), { cvv: '' });

this.recurly.token(builder(example), (err, token) => {
assert(err.code === 'validation');
assert(err.fields.length === 1);
assert(~err.fields.indexOf('cvv'));
assert(!token);
done();
});
});
});

describe('when cvv is invalid', function () {
it('produces a validation error', function (done) {
const example = merge(clone(valid), { cvv: '23783564' });

this.recurly.token(builder(example), (err, token) => {
assert(err.code === 'validation');
assert(err.fields.length === 1);
assert(~err.fields.indexOf('cvv'));
assert(!token);
done();
});
});
});

describe('when cvv is valid', function () {
it('produces a validation error', function (done) {
const example = merge(clone(valid), { cvv: '123' });

this.recurly.token(builder(example), (err, token) => {
assert(!err);
assert(token);
done();
});
});
});
});

describe('when given additional required fields', function () {
beforeEach(function (done) {
this.recurly = initRecurly({
Expand Down

0 comments on commit c2a7a19

Please sign in to comment.