Skip to content
Browse files

Updated tests.

  • Loading branch information...
1 parent 3d031f6 commit 2708d7f93809222de476af6ccbf40062e7d2c7b4 @xtian committed Dec 16, 2012
View
4 package.json
@@ -11,8 +11,8 @@
}
, "dependencies": { "request": "~2" }
, "devDependencies":
- { "jshint": ">= 1"
- , "tap": ">= 0.4"
+ { "jshint": "~1"
+ , "tap": "~0.4"
}
, "scripts": { "test": "make test" }
, "license": "MIT"
View
56 tests/arena.test.js
@@ -1,56 +0,0 @@
-var test = require('tap').test,
- armory = require('../').defaults({
- region: 'us',
- battlegroup: 'Vindication',
- realm: 'Shadowmoon'
- });
-
-test('single team', function(test) {
- armory.arena({ name: 'No Dairy', size: '2v2' }, function(err, team) {
- test.error(err);
- test.ok(team);
- test.equal(team.name, 'No Dairy');
- test.end();
- });
-});
-
-test('non-existent team', function(test) {
- armory.arena({ name: 'foo', size: '2v2' }, function(err, team) {
- test.ok(err);
- test.end();
- });
-});
-
-test('empty options', function(test) {
- armory.arena({}, function(err, team) {
- test.ok(err);
- test.end();
- });
-});
-
-test('single ladder', function(test) {
- armory.ladder({ name: '2v2' }, function(err, ladder) {
- test.error(err);
- test.ok(Array.isArray(ladder));
- test.ok(ladder.length);
- test.end();
- });
-});
-
-test('non-existent ladder', function(test) {
- armory.ladder({ name: 'foo' }, function(err, ladder) {
- test.ok(err);
- test.end();
- });
-});
-
-test('non-existent battlegroup', function(test) {
- armory.ladder({
- name: '2v2',
- battlegroup: 'foo'
-
- }, function(err, ladder) {
- test.ok(err);
- test.end();
- });
-});
View
91 tests/auction.test.js
@@ -1,91 +0,0 @@
-var test = require('tap').test,
- armory = require('../').defaults({ region: 'us' });
-
-test('single realm', function(test) {
- armory.auction('Shadowmoon', function(err, urls) {
- test.error(err);
- test.ok(Array.isArray(urls));
- test.ok(urls.length);
- test.end();
- });
-});
-
-test('region', function(test) {
- armory.auction({
- name: 'Свежеватель Душ',
- region: 'eu'
-
- }, function(err, urls) {
- test.error(err);
- test.ok(Array.isArray(urls));
- test.ok(urls.length);
- test.end();
- });
-});
-
-test('lastModified', function(test) {
- armory.auction('Shadowmoon', function(err, urls) {
- test.error(err);
- test.ok(Array.isArray(urls));
- test.ok(urls[0].lastModified);
-
- var lastModified = urls[0].lastModified;
-
- armory.auction({
- name: 'Shadowmoon',
- lastModified: lastModified
-
- }, function(err, res) {
- test.error(err);
- test.equal(res, undefined);
- test.end();
- });
- });
-});
-
-test('single realm data', function(test) {
- armory.auctionData('Shadowmoon', function(err, res) {
- test.error(err);
- test.ok(res);
- test.ok(res.alliance);
- test.ok(res.horde);
- test.ok(res.neutral);
- test.end();
- });
-});
-
-test('data with region', function(test) {
- armory.auctionData({
- name: 'Tarren Mill',
- region: 'eu'
-
- }, function(err, res) {
- test.error(err);
- test.ok(res);
- test.ok(res.alliance);
- test.ok(res.horde);
- test.ok(res.neutral);
- test.end();
- });
-});
-
-test('data with lastModified', function(test) {
- armory.auction('Shadowmoon', function(err, urls) {
- test.error(err);
- test.ok(urls);
- test.ok(urls[0].lastModified);
-
- var lastModified = urls[0].lastModified;
-
- armory.auctionData({
- name: 'Shadowmoon',
- lastModified: lastModified
-
- }, function(err, res) {
- test.error(err);
- test.equal(res, undefined);
- test.end();
- });
- });
-});
-
View
79 tests/battlepet.test.js
@@ -0,0 +1,79 @@
+var test = require('tap').test
+ , armory = require('../')
+
+var Stream = require('stream').Stream
+
+test('battlePetAbility', function(t) {
+ var options = { id: 222, region: 'us' }
+
+ t.test('should build correct url and response', function(t) {
+ armory.battlePetAbility(options, function(err, body, res) {
+ t.notOk(err, 'no error returned')
+ t.equal(res.req.path, '/api/wow/battlePet/ability/222', 'built api url')
+ t.equal(res.statusCode, 200, 'returned 200')
+ t.type(body, 'object', 'returned an object')
+ t.end()
+ })
+ })
+
+ t.test('should return a Stream if no callback is passed', function(t) {
+ var res = armory.battlePetAbility(options)
+
+ t.type(res, Stream)
+ t.end()
+ })
+})
+
+test('battlePetSpecies', function(t) {
+ var options = { id: 444, region: 'us' }
+
+ t.test('should build correct url and response', function(t) {
+ armory.battlePetSpecies(options, function(err, body, res) {
+ t.notOk(err, 'no error returned')
+ t.equal(res.req.path, '/api/wow/battlePet/species/444', 'built api url')
+ t.equal(res.statusCode, 200, 'returned 200')
+ t.type(body, 'object', 'returned an object')
+ t.end()
+ })
+ })
+
+ t.test('should return a Stream if no callback is passed', function(t) {
+ var res = armory.battlePetSpecies(options)
+
+ t.type(res, Stream)
+ t.end()
+ })
+})
+
+test('battlePetStats', function(t) {
+ var options =
+ { id: 258
+ , breedId: 5
+ , level: 25
+ , qualityId: 4
+ , region: 'us'
+ }
+
+ t.test('should build correct url and response', function(t) {
+ armory.battlePetStats(options, function(err, body, res) {
+ t.notOk(err, 'no error returned')
+
+ t.similar(
+ res.req.path
+ , '/api/wow/battlePet/stats/258?breedId=5&level=25&qualityId=4'
+ , 'built api url'
+ )
+
+ t.equal(res.statusCode, 200, 'returned 200')
+ t.type(body, 'object', 'returned an object')
+ t.end()
+ })
+ })
+
+ t.test('should return a Stream if no callback is passed', function(t) {
+ var res = armory.battlePetStats(options)
+
+ t.type(res, Stream)
+ t.end()
+ })
+})
View
85 tests/character.test.js
@@ -1,85 +0,0 @@
-var test = require('tap').test,
- armory = require('../').defaults({
- region: 'us',
- realm: 'Shadowmoon',
- name: 'Dargonaut'
- });
-
-test('single character', function(test) {
- armory.character(function(err, character) {
- test.error(err);
- test.ok(character);
- test.equal(character.name, 'Dargonaut');
- test.end();
- });
-});
-
-test('international name and server', function(test) {
- armory.character({
- name: 'Альвеона',
- realm: 'Свежеватель Душ',
- region: 'eu'
-
- }, function(err, character) {
- test.error(err);
- test.ok(character);
- test.equal(character.name, 'Альвеона');
- test.end();
- });
-});
-
-test('additional fields', function(test) {
- armory.character({ fields: ['items', 'talents'] }, function(err, res) {
- test.error(err);
- test.ok(res);
- test.ok(res.items);
- test.ok(Array.isArray(res.talents));
- test.end();
- });
-});
-
-test('additional fields with locale', function(test) {
- armory.character({
- fields: ['titles'],
- locale: 'es_MX'
-
- }, function(err, character) {
- test.error(err);
- test.ok(character);
- test.ok(character.titles);
- test.equal(character.titles[0].name,
- '%s, Campeón de los baldíos helados');
- test.end();
- });
-});
-
-test('lastModified', function(test) {
- armory.character(function(err, character) {
- test.error(err);
- test.ok(character);
- test.ok(character.lastModified);
-
- armory.character({
- lastModified: character.lastModified
-
- }, function(err, character) {
- test.error(err);
- test.equal(character, undefined);
- test.end();
- });
- });
-});
-
-test('non-existent character', function(test) {
- armory.character('foo', function(err, character) {
- test.ok(err);
- test.end();
- });
-});
-
-test('empty options', function(test) {
- require('../').character({}, function(err, character) {
- test.ok(err);
- test.end();
- });
-});
View
71 tests/data.test.js
@@ -1,49 +1,32 @@
-var test = require('tap').test,
- armory = require('../').defaults({ region: 'us' });
+var test = require('tap').test
+ , armory = require('../')
-test('region', function(test) {
- armory.races({ region: 'eu' }, function(err, races) {
- test.error(err);
- test.ok(Array.isArray(races));
- test.ok(races.length);
- test.end();
- });
-});
+var Stream = require('stream').Stream
-test('locale', function(test) {
- armory.races({ locale: 'es_MX' }, function(err, races) {
- test.error(err);
- test.ok(Array.isArray(races));
- test.ok(races.length);
- test.equal(races[0].name, 'Humano');
- test.end();
- });
-});
+var options = { region: 'us' }
-test('region and locale', function(test) {
- armory.races({ region: 'eu', locale: 'de_DE' }, function(err, races) {
- test.error(err);
- test.ok(Array.isArray(races));
- test.ok(races.length);
- test.equal(races[1].name, 'Mensch');
- test.end();
- });
-});
+;['battlegroups'
+, 'characterAchievements'
+, 'classes'
+, 'guildAchievements'
+, 'perks'
+, 'races'
+, 'rewards'
+].forEach(function(method) {
-test('battlegroups', function(test) {
- armory.battlegroups(function(err, results) {
- test.error(err);
- test.ok(Array.isArray(results));
- test.ok(results.length);
- test.end();
- });
-});
+ test(method + ' should build correct url and output', function(t) {
+ armory[method](options, function(err, body, res) {
+ t.notOk(err, 'no error returned')
+ t.type(body, Array, 'returned an array')
+ t.equal(res.statusCode, 200, 'returned 200')
+ t.end()
+ })
+ })
-test('characterAcheivements', function(test) {
- armory.characterAchievements(function(err, results) {
- test.error(err);
- test.ok(Array.isArray(results));
- test.ok(results.length);
- test.end();
- });
-});
+ test(method + ' should return Stream if no callback is passed', function(t) {
+ var res = armory[method](options)
+
+ t.type(res, Stream, 'returned a Stream')
+ t.end()
+ })
+})
View
22 tests/defaults.test.js
@@ -0,0 +1,22 @@
+var test = require('tap').test
+ , armory = require('../')
+
+test('should merge options with defaults', function(t) {
+ armory.realmStatus = function(options) {
+ t.equal(options.region, 'us')
+ t.equal(options.id, 0)
+ t.end()
+ }
+
+ armory.defaults({region: 'us'}).realmStatus({id: 0}, function() {})
+})
+
+test('should merge id param with defaults', function(t) {
+ armory.realmStatus = function(options) {
+ t.equal(options.region, 'us')
+ t.equal(options.id, 0)
+ t.end()
+ }
+
+ armory.defaults({region: 'us'}).realmStatus(0, function() {})
+})
View
193 tests/generic.test.js
@@ -0,0 +1,193 @@
+var test = require('tap').test
+ , armory = require('../')
+
+var Stream = require('stream').Stream
+
+test('achievement', function(t) {
+ var options = { id: 1705, region: 'us' }
+
+ t.test('should build correct url and response', function(t) {
+ armory.achievement(options, function(err, body, res) {
+ t.notOk(err, 'no error returned')
+ t.equal(res.req.path, '/api/wow/achievement/1705', 'built api url')
+ t.equal(res.statusCode, 200, 'returned 200')
+ t.type(body, 'object', 'returned an object')
+ t.end()
+ })
+ })
+
+ t.test('should return a Stream if no callback is passed', function(t) {
+ var res = armory.achievement(options)
+
+ t.type(res, Stream)
+ t.end()
+ })
+})
+
+test('auction', function(t) {
+ var options = { id: 'shadowmoon', region: 'us' }
+
+ t.test('should build correct url and response', function(t) {
+ armory.auction(options, function(err, body, res) {
+ t.notOk(err, 'no error returned')
+ t.equal(res.req.path, '/api/wow/auction/data/shadowmoon', 'built api url')
+ t.equal(res.statusCode, 200, 'returned 200')
+ t.type(body, Array, 'returned an array')
+ t.end()
+ })
+ })
+
+ t.test('should return a Stream if no callback is passed', function(t) {
+ var res = armory.auction(options)
+
+ t.type(res, Stream)
+ t.end()
+ })
+})
+
+test('challenge', function(t) {
+ var options = { id: 'shadowmoon', region: 'us' }
+
+ t.test('should build correct url and response', function(t) {
+ armory.challenge(options, function(err, body, res) {
+ t.notOk(err, 'no error returned')
+ t.equal(res.req.path, '/api/wow/challenge/shadowmoon', 'built api url')
+ t.equal(res.statusCode, 200, 'returned 200')
+ t.type(body, Array, 'returned an array')
+ t.end()
+ })
+ })
+
+ t.test('should return a Stream if no callback is passed', function(t) {
+ var res = armory.challenge(options)
+
+ t.type(res, Stream)
+ t.end()
+ })
+})
+
+test('challengeRegion', function(t) {
+ var options = { region: 'us' }
+
+ t.test('should build correct url and response', function(t) {
+ armory.challengeRegion(options, function(err, body, res) {
+ t.notOk(err, 'no error returned')
+ t.equal(res.req.path, '/api/wow/challenge/region', 'built api url')
+ t.equal(res.statusCode, 200, 'returned 200')
+ t.type(body, Array, 'returned an array')
+ t.end()
+ })
+ })
+
+ t.test('should return a Stream if no callback is passed', function(t) {
+ var res = armory.challengeRegion(options)
+
+ t.type(res, Stream)
+ t.end()
+ })
+})
+
+test('item', function(t) {
+ var options = { id: 28041, region: 'us' }
+
+ t.test('should build correct url and response', function(t) {
+ armory.item(options, function(err, body, res) {
+ t.notOk(err, 'no error returned')
+ t.equal(res.req.path, '/api/wow/item/28041', 'built api url')
+ t.equal(res.statusCode, 200, 'returned 200')
+ t.type(body, 'object', 'returned an object')
+ t.end()
+ })
+ })
+
+ t.test('should return a Stream if no callback is passed', function(t) {
+ var res = armory.item(options)
+
+ t.type(res, Stream)
+ t.end()
+ })
+})
+
+test('itemSet', function(t) {
+ var options = { id: 650, region: 'us' }
+
+ t.test('should build correct url and response', function(t) {
+ armory.itemSet(options, function(err, body, res) {
+ t.notOk(err, 'no error returned')
+ t.equal(res.req.path, '/api/wow/item/set/650', 'built api url')
+ t.equal(res.statusCode, 200, 'returned 200')
+ t.type(body, 'object', 'returned an object')
+ t.end()
+ })
+ })
+
+ t.test('should return a Stream if no callback is passed', function(t) {
+ var res = armory.itemSet(options)
+
+ t.type(res, Stream)
+ t.end()
+ })
+})
+
+test('quest', function(t) {
+ var options = { id: 11549, region: 'us' }
+
+ t.test('should build correct url and response', function(t) {
+ armory.quest(options, function(err, body, res) {
+ t.notOk(err, 'no error returned')
+ t.equal(res.req.path, '/api/wow/quest/11549', 'built api url')
+ t.equal(res.statusCode, 200, 'returned 200')
+ t.type(body, 'object', 'returned an object')
+ t.end()
+ })
+ })
+
+ t.test('should return a Stream if no callback is passed', function(t) {
+ var res = armory.quest(options)
+
+ t.type(res, Stream)
+ t.end()
+ })
+})
+
+test('recipe', function(t) {
+ var options = { id: 33288, region: 'us' }
+
+ t.test('should build correct url and response', function(t) {
+ armory.recipe(options, function(err, body, res) {
+ t.notOk(err, 'no error returned')
+ t.equal(res.req.path, '/api/wow/recipe/33288', 'built api url')
+ t.equal(res.statusCode, 200, 'returned 200')
+ t.type(body, 'object', 'returned an object')
+ t.end()
+ })
+ })
+
+ t.test('should return a Stream if no callback is passed', function(t) {
+ var res = armory.recipe(options)
+
+ t.type(res, Stream)
+ t.end()
+ })
+})
+
+test('spell', function(t) {
+ var options = { id: 6197, region: 'us' }
+
+ t.test('should build correct url and response', function(t) {
+ armory.spell(options, function(err, body, res) {
+ t.notOk(err, 'no error returned')
+ t.equal(res.req.path, '/api/wow/spell/6197', 'built api url')
+ t.equal(res.statusCode, 200, 'returned 200')
+ t.type(body, 'object', 'returned an object')
+ t.end()
+ })
+ })
+
+ t.test('should return a Stream if no callback is passed', function(t) {
+ var res = armory.spell(options)
+
+ t.type(res, Stream)
+ t.end()
+ })
+})
View
53 tests/get.test.js
@@ -0,0 +1,53 @@
+var test = require('tap').test
+ , armory = require('../')
+
+var IncomingMessage = require('http').IncomingMessage
+ , Stream = require('stream').Stream
+
+var options = { locale: 'en_US', _query: {}, region: 'us' }
+
+test('_get', function(t) {
+ armory._get('/realm/status', options, function(err, body, res) {
+ t.type(body, 'object', 'body was parsed from JSON')
+ t.type(res, IncomingMessage, 'full response passed as third parameter')
+
+ t.equal(res.req.getHeader('Host'), 'us.battle.net', 'built battle.net url')
+ t.equal(res.req.path, '/api/wow/realm/status?locale=en_US', 'built api path')
+
+ t.end()
+ })
+})
+
+test('should throw if no region is provided', function(t) {
+ var fn = function() { armory._get('/realm/status', { _query: {} }) }
+ , err = new Error('region must be provided')
+
+ t.throws(fn, err, 'threw for undefined region')
+ t.end()
+})
+
+test('should create Error object out of error reason', function(t) {
+ armory._get('/0', options, function(err) {
+ t.type(err, Error, 'Error passed as first param')
+ t.end()
+ })
+})
+
+test('should return Stream if no callback is passed', function(t) {
+ var res = armory._get('/realm/status', options)
+
+ t.type(res, Stream, 'returned a Stream')
+ t.end()
+})
+
+test('auth', function(t) {
+ armory.privateKey = armory.publicKey = 'test'
+
+ armory._get('/realm/status', options, function(err, body, res) {
+ var time = new Date(res.req.getHeader('Date')).getTime()
+ t.notOk(Number.isNaN(time), 'valid date header set')
+
+ t.similar(res.req.getHeader('Authorization'), /BNET test:/, 'header set')
+ t.end()
+ })
+})
View
59 tests/guild.test.js
@@ -1,59 +0,0 @@
-var test = require('tap').test,
- armory = require('../').defaults({
- region: 'us',
- realm: 'Shadowmoon',
- name: 'The Gentlemens Club'
- });
-
-test('single guild', function(test) {
- armory.guild(function(err, guild) {
- test.error(err);
- test.ok(guild);
- test.equal(guild.name, 'The Gentlemens Club');
- test.end();
- });
-});
-
-test('additional fields', function(test) {
- armory.guild({ fields: ['members', 'achievements'] }, function(err, guild) {
- test.error(err);
- test.ok(guild);
- test.ok(Array.isArray(guild.members));
- test.ok(guild.members.length);
- test.ok(guild.achievements);
- test.ok(Array.isArray(guild.achievements.criteria));
- test.ok(guild.achievements.criteria.length);
- test.end();
- });
-});
-
-test('lastModified', function(test) {
- armory.guild(function(err, guild) {
- test.error(err);
- test.ok(guild);
- test.ok(guild.lastModified);
-
- armory.guild({
- lastModified: guild.lastModified
-
- }, function(err, guild) {
- test.error(err);
- test.equal(guild, undefined);
- test.end();
- });
- });
-});
-
-test('non-existent guild', function(test) {
- armory.guild('foo', function(err, guild) {
- test.ok(err);
- test.end();
- });
-});
-
-test('empty options', function(test) {
- require('../').guild({}, function(err, guild) {
- test.ok(err);
- test.end();
- });
-});
View
27 tests/item.test.js
@@ -1,27 +0,0 @@
-var test = require('tap').test,
- armory = require('../').defaults({ region: 'us', fallback: false });
-
-test('single item', function(test) {
- armory.item(27987, function(err, item) {
- test.error(err);
- test.ok(item);
- test.equal(item.id, 27987);
- test.end();
- });
-});
-
-test('non-existent item', function(test) {
- armory.item(0, function(err, item) {
- test.ok(err);
- test.end();
- });
-});
-
-test('4.3 item', function(test) {
- armory.item({ id: 72829, fallback: true }, function(err, item) {
- test.error(err);
- test.ok(item);
- test.equal(item.id, 72829);
- test.end();
- });
-});
View
106 tests/pvp.test.js
@@ -0,0 +1,106 @@
+var test = require('tap').test
+ , armory = require('../')
+
+var Stream = require('stream').Stream
+
+test('arena', function(t) {
+ var options =
+ { name: 'Staker cheated on his GF'
+ , realm: 'shadowmoon'
+ , region: 'us'
+ , size: '5v5'
+ }
+
+ t.test('should build correct url and response', function(t) {
+ armory.arena(options, function(err, body, res) {
+ t.notOk(err, 'no error returned')
+
+ t.equal(
+ res.req.path
+ , '/api/wow/arena/shadowmoon/5v5/Staker%20cheated%20on%20his%20GF'
+ , 'built api url'
+ )
+
+ t.equal(res.statusCode, 200, 'returned 200')
+ t.type(body, 'object', 'returned an object')
+ t.end()
+ })
+ })
+
+ t.test('should return a Stream if no callback is passed', function(t) {
+ var res = armory.arena(options)
+
+ t.type(res, Stream)
+ t.end()
+ })
+})
+
+test('arenaLadder', function(t) {
+ var options =
+ { battlegroup: 'vindication'
+ , id: '2v2'
+ , region: 'us'
+ , asc: false
+ , page: 2
+ , size: 10
+ }
+
+ t.test('should build correct url and response', function(t) {
+ armory.arenaLadder(options, function(err, body, res) {
+ t.notOk(err, 'no error returned')
+
+ t.equal(
+ res.req.path
+ , '/api/wow/pvp/arena/vindication/2v2?asc=false&page=2&size=10'
+ , 'built api url'
+ )
+
+ t.equal(res.statusCode, 200, 'returned 200')
+ t.type(body, Array, 'returned an array')
+ t.end()
+ })
+ })
+
+ t.test('should return a Stream if no callback is passed', function(t) {
+ var res = armory.arenaLadder(options)
+
+ t.type(res, Stream)
+ t.end()
+ })
+})
+
+test('rbgLadder', function(t) {
+ var options =
+ { region: 'us'
+ , asc: false
+ , page: 2
+ , size: 10
+ }
+
+ t.test('should build correct url and response', function(t) {
+ armory.rbgLadder(options, function(err, body, res) {
+ t.notOk(err, 'no error returned')
+
+ t.equal(
+ res.req.path
+ , '/api/wow/pvp/ratedbg/ladder?asc=false&page=2&size=10'
+ , 'built api url'
+ )
+
+ t.equal(options._query.asc, false, 'asc query param set')
+ t.equal(options._query.page, 2, 'page query param set')
+ t.equal(options._query.size, 10, 'size query param set')
+
+ t.equal(res.statusCode, 200, 'returned 200')
+ t.type(body, Array, 'returned an array')
+ t.end()
+ })
+ })
+
+ t.test('should return a Stream if no callback is passed', function(t) {
+ var res = armory.rbgLadder(options)
+
+ t.type(res, Stream)
+ t.end()
+ })
+})
View
50 tests/quest.test.js
@@ -1,50 +0,0 @@
-var test = require('tap').test,
- armory = require('../').defaults({ region: 'us' });
-
-test('single quest', function(test) {
- armory.quest(11546, function(err, quest) {
- test.error(err);
- test.ok(quest);
- test.equal(quest.id, 11546);
- test.end();
- });
-});
-
-test('region', function(test) {
- armory.quest({ id: 11546, region: 'eu' }, function(err, quest) {
- test.error(err);
- test.ok(quest);
- test.equal(quest.id, 11546);
- test.end();
- });
-});
-
-test('locale', function(test) {
- armory.quest({ id: 11546, locale: 'de_DE' }, function(err, quest) {
- test.error(err);
- test.ok(quest);
- test.equal(quest.id, 11546);
- test.end();
- });
-});
-
-test('region and locale', function(test) {
- armory.quest({
- id: 11546,
- region: 'eu',
- locale: 'de_DE'
-
- }, function(err, quest) {
- test.error(err);
- test.ok(quest);
- test.equal(quest.id, 11546);
- test.end();
- });
-});
-
-test('non-existent quest', function(test) {
- armory.quest(0, function(err, quest) {
- test.ok(err);
- test.end();
- });
-});
View
194 tests/realm.test.js
@@ -1,142 +1,52 @@
-var test = require('tap').test,
- armory = require('../').defaults({ region: 'us' });
-
-test('all US realms', function(test) {
- armory.realmStatus(function(err, realms) {
- test.error(err);
- test.ok(Array.isArray(realms));
- test.ok(realms.length > 1);
- test.ok(realms[0].slug);
-
- test.end();
- });
-});
-
-test('all US realms with locale', function(test) {
- armory.realmStatus({ locale: 'es_MX' }, function(err, realms) {
- test.error(err);
- test.ok(Array.isArray(realms));
- test.ok(realms.length > 1);
- test.ok(realms[0].slug);
-
- test.end();
- });
-});
-
-test('all EU realms', function(test) {
- armory.realmStatus({ region: 'eu' }, function(err, realms) {
- test.error(err);
- test.ok(Array.isArray(realms));
- test.ok(realms.length > 1);
- test.ok(realms[0].slug);
-
- test.end();
- });
-});
-
-test('all EU realms with locale', function(test) {
- armory.realmStatus({
- region: 'eu',
- locale: 'fr_FR'
-
- }, function(err, realms) {
- test.error(err);
- test.ok(Array.isArray(realms));
- test.ok(realms.length > 1);
- test.ok(realms[0].slug);
-
- test.end();
- });
-});
-
-test('single US realm', function(test) {
- armory.realmStatus('Shadowmoon', function(err, realms) {
- test.error(err);
- test.ok(Array.isArray(realms));
-
- realms = realms[0];
- test.equal(realms.name, 'Shadowmoon');
- test.equal(realms.slug, 'shadowmoon');
-
- test.end();
- });
-});
-
-test('single EU realm', function(test) {
- armory.realmStatus({
- name: 'Свежеватель Душ',
- region: 'eu'
-
- }, function(err, realms) {
- test.error(err);
- test.ok(Array.isArray(realms));
-
- realms = realms[0];
- test.equal(realms.name, 'Soulflayer');
- test.equal(realms.slug, 'soulflayer');
-
- test.end();
- });
-});
-
-test('single EU realm with locale', function(test) {
- armory.realmStatus({
- name: 'Свежеватель Душ',
- region: 'eu',
- locale: 'ru_RU'
-
- }, function(err, realms) {
- test.error(err);
- test.ok(Array.isArray(realms));
-
- realms = realms[0];
- test.equal(realms.name, 'Свежеватель Душ');
- test.equal(realms.slug, 'свежеватель-душ');
-
- test.end();
- });
-});
-
-test('multiple US realms', function(test) {
- armory.realmStatus(['Cho\'gall', 'Shadowmoon'], function(err, realms) {
- test.error(err);
- test.ok(Array.isArray(realms));
- test.equal(realms.length, 2);
-
- test.equal(realms[0].name, 'Shadowmoon');
- test.equal(realms[0].slug, 'shadowmoon');
- test.equal(realms[1].name, 'Cho\'gall');
- test.equal(realms[1].slug, 'chogall');
-
- test.end();
- });
-});
-
-test('multiple EU realms', function(test) {
- armory.realmStatus({
- name: ['Свежеватель Душ', 'Festung der Stürme'],
- region: 'eu'
-
- }, function(err, realms) {
-
- test.error(err);
- test.ok(Array.isArray(realms));
- test.equal(realms.length, 2);
-
- test.equal(realms[0].name, 'Soulflayer');
- test.equal(realms[0].slug, 'soulflayer');
- test.equal(realms[1].name, 'Festung der Stürme');
- test.equal(realms[1].slug, 'festung-der-sturme');
-
- test.end();
- });
-});
-
-test('non-existent realm', function(test) {
- armory.realmStatus('foo', function(err, realms) {
- test.error(err);
- test.ok(realms.length > 1);
-
- test.end();
- });
-});
+var test = require('tap').test
+ , armory = require('../')
+
+var Stream = require('stream').Stream
+
+test('realmStatus', function(t) {
+ var options = { id: 'shadowmoon', region: 'us' }
+
+ t.test('should build correct url and response', function(t) {
+ armory.realmStatus(options, function(err, body, res) {
+ t.notOk(err, 'no error returned')
+
+ t.equal(
+ res.req.path
+ , '/api/wow/realm/status?realm=shadowmoon'
+ , 'built api url'
+ )
+
+ t.equal(options._query.realm, 'shadowmoon', 'realm query param set')
+ t.equal(res.statusCode, 200, 'returned 200')
+ t.type(body, Array, 'returned an array')
+ t.equal(body.length, 1, 'returned one realm')
+
+ t.end()
+ })
+ })
+
+ t.test('should accept array of realms', function(t) {
+ var options = { id: ['shadowmoon', 'nazgrel'], region: 'us' }
+
+ armory.realmStatus(options, function(err, body) {
+ t.notOk(err, 'no error returned')
+
+ t.similar(
+ options._query.realm
+ , ['shadowmoon', 'nazgrel']
+ , 'realm query param set'
+ )
+
+ t.type(body, Array, 'returned an array')
+ t.equal(body.length, 2, 'returned two realms')
+ t.end()
+ })
+ })
+
+ t.test('should return a Stream if no callback is passed', function(t) {
+ var res = armory.realmStatus(options)
+
+ t.type(res, Stream)
+ t.end()
+ })
+})
View
109 tests/utils.test.js
@@ -0,0 +1,109 @@
+var test = require('tap').test
+ , utils = require('../utils')
+
+test('getKey', function(t) {
+ var obj = { key: 'value', 'null': null }
+
+ t.equal(utils.getKey(obj, 'key'), 'value', 'got value of key')
+ t.equal(utils.getKey(obj, 'null'), obj, 'got obj because key was null')
+ t.equal(utils.getKey(obj, 'blank'), obj, 'got obj because key was undefined')
+ t.equal(utils.getKey(), undefined, 'got undefined because obj was missing')
+
+ t.end()
+})
+
+test('wrap', function(t) {
+ var obj =
+ { privateKey: 1
+ , publicKey: 1
+ , defaults: 1
+ , _get: 1
+ , key: 1
+ }
+
+ var wrapper = function(val) { return val + 1 }
+ , wrapped = utils.wrap(obj, wrapper)
+
+ t.equal(wrapped.key, 2, 'got key with wrapper applied')
+ t.equal(wrapped.privateKey, 1, 'privateKey excluded from wrapper')
+ t.equal(wrapped.publicKey, 1, 'publicKey excluded from wrapper')
+ t.equal(wrapped.defaults, 1, 'defaults excluded from wrapper')
+ t.equal(wrapped._get, 1, '_get excluded from wrapper')
+
+ t.end()
+})
+
+test('initParams', function(t) {
+ t.type(utils.initParams(), 'function', 'returned wrapped function')
+
+ t.test('should initialize options object if callback passed', function(t) {
+ var fn = utils.initParams(function(options) {
+ t.type(options, 'object', 'options was initialized')
+ t.type(options.headers, 'object', 'headers was initialized')
+ t.type(options._query, 'object', '_query was initialized')
+ })
+
+ fn(function() {})
+ t.end()
+ })
+
+ t.test('should set the id prop if options object not passed', function(t) {
+ var fn = utils.initParams(function(options) {
+ t.equal(options.id, 1, 'id property was set to passed number param')
+ })
+
+ fn(1)
+ t.end()
+ })
+
+ t.test('should set the id prop if array passed', function(t) {
+ var fn = utils.initParams(function(options) {
+ t.deepEqual(options.id, [1], 'id property was set to passed array param')
+ })
+
+ fn([1])
+ t.end()
+ })
+
+ t.test('should copy name prop to id prop', function(t) {
+ var fn = utils.initParams(function(options) {
+ t.equal(options.id, 1, 'id was set to value of name property')
+ })
+
+ fn({ name: 1 })
+ t.end()
+ })
+
+ t.test('should call function with the passed context', function(t) {
+ var self = {}
+ var fn = utils.initParams(function() {
+ t.equal(this, self, 'this value was equal to passed context param')
+ }, self)
+
+ fn({})
+ t.end()
+ })
+
+ t.end()
+})
+
+test('merge', function(t) {
+ var obj1 = { one: 1, two: null }
+ , obj2 = { one: 11, two: 2, three: 3 }
+ , merged = utils.merge(obj1, obj2)
+
+ t.equal(merged.one, 1, 'present value was not overwritten')
+ t.equal(merged.two, 2, 'null value was overwritten')
+ t.equal(merged.three, 3, 'undefined property was set')
+ t.end()
+})
+
+test('pick', function(t) {
+ var obj = { one: 1, two: 2, three: 3 }
+ , picked = utils.pick(obj, ['one', 'three'])
+
+ t.equal(picked.one, 1, '"one" was copied to new object')
+ t.equal(picked.two, undefined, '"two" was not copied to new object')
+ t.equal(picked.three, 3, '"three" was copied to new object')
+ t.end()
+})

0 comments on commit 2708d7f

Please sign in to comment.
Something went wrong with that request. Please try again.