File tree Expand file tree Collapse file tree 7 files changed +130
-24
lines changed
Expand file tree Collapse file tree 7 files changed +130
-24
lines changed Original file line number Diff line number Diff line change @@ -28,4 +28,5 @@ build/Release
2828node_modules
2929
3030# IDE Directory
31- .vscode /
31+ .vscode /
32+ config \. json
Original file line number Diff line number Diff line change 1+ /**
2+ * config.json =
3+ * {
4+ * apikey: 'supersecret'
5+ * }
6+ */
7+ const config = require ( './config.json' )
8+
9+ const AchievementTest = require ( './tests/access/community/wow/achievements/retrieve-achievement' )
10+ const test = new AchievementTest ( { apikey : config . apikey } )
11+
12+ test . execute ( ) . then ( response => console . log ( response ) )
Original file line number Diff line number Diff line change 22 "name" : " @targetdummy/test-runner" ,
33 "version" : " 0.0.1" ,
44 "description" : " The test runner for TargetDummy" ,
5+ "main" : " index.js" ,
56 "author" : {
67 "name" : " Alcha" ,
78 "email" : " alcha@paranoiddevs.com" ,
1213 "type" : " git" ,
1314 "url" : " https://github.com/bnettargetdummy/test-runner.git"
1415 },
16+ "scripts" : {
17+ "start" : " node index.js"
18+ },
1519 "dependencies" : {
1620 "@targetdummy/logger" : " BNetTargetDummy/logger" ,
17- "async" : " 2.5.0" ,
1821 "blizzard.js" : " 1.7.0"
1922 },
2023 "devDependencies" : {
Original file line number Diff line number Diff line change @@ -2,9 +2,10 @@ const Base = require('./base')
22
33class Access extends Base {
44 constructor ( options ) {
5- super ( )
5+ super ( options )
66
7- this . options = options
7+ this . name = 'API Access Test'
8+ this . description = 'For testing access to the Battle.net API.'
89 }
910}
1011
Original file line number Diff line number Diff line change 1+ let blizzard
2+
13class Base {
24 constructor ( options ) {
3- this . options = options
5+ if ( options . name !== undefined ) this . name = options . name
6+ else this . name = ''
7+
8+ if ( options . description !== undefined ) this . description = options . description
9+ else this . description = ''
10+
11+ if ( options . path !== undefined ) this . path = options . path
12+ else this . path = ''
13+
14+ if ( options . onPreExecute !== undefined ) this . onPreExecute = options . onPreExecute
15+ else this . onPreExecute = function ( ) { }
16+
17+ if ( options . onExecute !== undefined ) this . onExecute = options . onExecute
18+ else this . onExecute = function ( ) { }
19+
20+ if ( options . onPostExecute !== undefined ) this . onPostExecute = options . onPostExecute
21+ else this . onPostExecute = function ( ) { }
22+
23+ if ( options . apikey !== undefined ) this . apikey = options . apikey
24+ else this . apikey = ''
25+
26+ if ( options . region !== undefined ) this . region = options . region
27+ else this . region = ''
28+
29+ blizzard = require ( 'blizzard.js' ) . initialize ( { apikey : this . apikey } )
30+ }
31+
32+ executeWoWRequest ( request ) {
33+ return new Promise ( ( resolve , reject ) => {
34+ switch ( request . type ) {
35+ case 'achievement' :
36+ blizzard . wow . achievement ( request . args )
37+ . then ( response => resolve ( response ) )
38+ . catch ( err => resolve ( err . response ) )
39+ break
40+ }
41+ } )
442 }
543}
644
Original file line number Diff line number Diff line change 1+ const Access = require ( '../../../../../src/access' )
2+
3+ class RetrieveAchievement extends Access {
4+ constructor ( options ) {
5+ super ( options )
6+
7+ this . name = 'WoWAchievement Test'
8+ this . description = 'Tests the WoW Community Achievement endpoint.'
9+ }
10+
11+ pass ( args ) {
12+ return {
13+ result : 'PASS' ,
14+ status : args . status ,
15+ data : args . data
16+ }
17+ }
18+
19+ fail ( args ) {
20+ return {
21+ result : 'FAIL' ,
22+ status : args . status ,
23+ reason : args . data . detail
24+ }
25+ }
26+
27+ requestObject ( ) {
28+ return {
29+ game : 'wow' ,
30+ type : 'achievement' ,
31+ args : {
32+ id : 2144 ,
33+ origin : 'us'
34+ }
35+ }
36+ }
37+
38+ execute ( ) {
39+ return new Promise ( ( resolve , reject ) => {
40+ super . executeWoWRequest ( this . requestObject ( ) ) . then ( response => {
41+ switch ( parseInt ( response . status ) ) {
42+ case 200 :
43+ resolve ( this . pass ( response ) )
44+ break
45+
46+ case 403 :
47+ resolve ( this . fail ( response ) )
48+ break
49+
50+ default :
51+ console . log ( response )
52+ }
53+ } )
54+ } )
55+ }
56+ }
57+
58+ module . exports = RetrieveAchievement
You can’t perform that action at this time.
0 commit comments