Skip to content

Commit

Permalink
First version of a functional test
Browse files Browse the repository at this point in the history
The first version of an actual test. This one tests access to the WoW Community Achievement API and verifies it's available, returning the results.
  • Loading branch information
4lch4 committed Sep 9, 2017
1 parent 970316c commit 13ebf4a
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ build/Release
node_modules

# IDE Directory
.vscode/
.vscode/
config\.json
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* config.json =
* {
* apikey: 'supersecret'
* }
*/
const config = require('./config.json')

const AchievementTest = require('./tests/access/community/wow/achievements/retrieve-achievement')
const test = new AchievementTest({apikey: config.apikey})

test.execute().then(response => console.log(response))
31 changes: 12 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@targetdummy/test-runner",
"version": "0.0.1",
"description": "The test runner for TargetDummy",
"main": "index.js",
"author": {
"name": "Alcha",
"email": "[email protected]",
Expand All @@ -12,9 +13,11 @@
"type": "git",
"url": "https://github.com/bnettargetdummy/test-runner.git"
},
"scripts": {
"start": "node index.js"
},
"dependencies": {
"@targetdummy/logger": "BNetTargetDummy/logger",
"async": "2.5.0",
"blizzard.js": "1.7.0"
},
"devDependencies": {
Expand Down
5 changes: 3 additions & 2 deletions src/access.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ const Base = require('./base')

class Access extends Base {
constructor (options) {
super()
super(options)

this.options = options
this.name = 'API Access Test'
this.description = 'For testing access to the Battle.net API.'
}
}

Expand Down
40 changes: 39 additions & 1 deletion src/base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
let blizzard

class Base {
constructor (options) {
this.options = options
if (options.name !== undefined) this.name = options.name
else this.name = ''

if (options.description !== undefined) this.description = options.description
else this.description = ''

if (options.path !== undefined) this.path = options.path
else this.path = ''

if (options.onPreExecute !== undefined) this.onPreExecute = options.onPreExecute
else this.onPreExecute = function () {}

if (options.onExecute !== undefined) this.onExecute = options.onExecute
else this.onExecute = function () {}

if (options.onPostExecute !== undefined) this.onPostExecute = options.onPostExecute
else this.onPostExecute = function () {}

if (options.apikey !== undefined) this.apikey = options.apikey
else this.apikey = ''

if (options.region !== undefined) this.region = options.region
else this.region = ''

blizzard = require('blizzard.js').initialize({apikey: this.apikey})
}

executeWoWRequest (request) {
return new Promise((resolve, reject) => {
switch (request.type) {
case 'achievement':
blizzard.wow.achievement(request.args)
.then(response => resolve(response))
.catch(err => resolve(err.response))
break
}
})
}
}

Expand Down
58 changes: 58 additions & 0 deletions tests/access/community/wow/achievements/retrieve-achievement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const Access = require('../../../../../src/access')

class RetrieveAchievement extends Access {
constructor (options) {
super(options)

this.name = 'WoWAchievement Test'
this.description = 'Tests the WoW Community Achievement endpoint.'
}

pass (args) {
return {
result: 'PASS',
status: args.status,
data: args.data
}
}

fail (args) {
return {
result: 'FAIL',
status: args.status,
reason: args.data.detail
}
}

requestObject () {
return {
game: 'wow',
type: 'achievement',
args: {
id: 2144,
origin: 'us'
}
}
}

execute () {
return new Promise((resolve, reject) => {
super.executeWoWRequest(this.requestObject()).then(response => {
switch (parseInt(response.status)) {
case 200:
resolve(this.pass(response))
break

case 403:
resolve(this.fail(response))
break

default:
console.log(response)
}
})
})
}
}

module.exports = RetrieveAchievement

0 comments on commit 13ebf4a

Please sign in to comment.