-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathravenfall.test.js
113 lines (112 loc) · 4.08 KB
/
ravenfall.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const {describe} = require('mocha');
const assert = require('assert');
const {expect} = require('chai');
const sinon = require('sinon');
describe('RavenFall UT', function() {
const config = require('./cred');
const Ravenfall = require('./ravenfall');
const r = new Ravenfall(config);
it('1000 exp eq Level 9', function() {
assert(r.ExperienceToLevel(1000) === 9);
});
it('1000 exp eq 16% progress', function() {
assert(r.Progress(1000) === '16%');
});
it('1000 exp has 155exp to go', function() {
assert(r.LevelToExperience(10)-1000 === 155);
});
it('SortByPower - weapon power 1,2,3 sorted to 3,2,1', function() {
const sortedArr = [{weaponPower: 1}, {weaponPower: 2}, {weaponPower: 3}].sort(r.SortByPower);
assert(sortedArr[0].weaponPower === 3);
});
it('SortByPower - armor power 1,2,3 sorted to 3,2,1', function() {
const sortedArr = [{armorPower: 1}, {armorPower: 2}, {armorPower: 3}].sort(r.SortByPower);
assert(sortedArr[0].armorPower === 3);
});
it('sameType should return true for [] and []', function() {
assert(r.sameType([], []) === true);
});
it('sameType should return false for [] and {}', function() {
assert(r.sameType([], {}) === false);
});
it('isArray should return true for [] and false for {}', function() {
assert(r.isArray({}) === false);
assert(r.isArray([]) === true);
});
it('allOfType should return true', function() {
const exampleObj = {id: 1, name: 'asd', test: '123123'};
const exArr = [exampleObj, exampleObj, exampleObj];
assert(r.allOfType(exampleObj, exArr) === true);
});
it('allOfType should return false', function() {
const exampleObj = {id: 1, name: 'asd', test: '123123'};
const badObj = {id: 1, names: 'asd', test: '123123'};
const exArr = [exampleObj, exampleObj, badObj];
assert(r.allOfType(exampleObj, exArr) === false);
});
it('compareProps should return 0', function() {
const exampleObj = {id: 1, name: 'asd', test: '123123'};
expect(r.compareProps(exampleObj, exampleObj).length).to.be.equal(0);
});
it('compareProps should return 1', function() {
const exampleObj = {id: 1, name: 'asd', test: '123123'};
const badObj = {id: 1, names: 'asd', test: '123123'};
const result = r.compareProps(badObj, exampleObj);
expect(result.length).to.be.equal(1);
expect(result[0]).to.be.equal('name');
});
it('Parameterless setClientHeader should standard header', function(next) {
r.SetClientHeader().then(function(data) {
expect(data['Content-Type']).to.be.equal('application/json, charset=utf-8');
next();
});
});
it('ravenFallAuth should return a token', function(next) {
r.RavenFallAuth(config.username, config.password).then(function(data) {
expect(data).to.not.be.undefined;
next();
}).catch(function(err) {
expect(err).to.be.undefined;
next();
});
});
it('getAuthToken uninitiated should return a JWT', function(next) {
r.GetAuthToken().then(function(data) {
expect(data).to.not.be.undefined;
next();
}).catch(function(err) {
expect(err).to.be.undefined;
next();
});
});
it('getAuthToken multiple times should return same valid token', function(done) {
let firstToken = {};
r.GetAuthToken().then(function(data) {
expect(data).to.not.be.undefined;
firstToken = data;
r.GetAuthToken().then(function(data2) {
expect(data2).to.not.be.undefined;
expect(r.compareProps(firstToken, data2).length).to.be.equal(0);
expect(firstToken.token).to.be.equal(data2.token);
done();
}).catch(function(err) {
expect(err).to.be.undefined;
done();
});
}).catch(function(err) {
expect(err).to.be.undefined;
done();
});
});
it('GetItems should store available items from API to class', function(done) {
r.GetItems().then(function(data) {
expect(data).to.not.be.undefined;
expect(data.data).to.not.be.undefined;
expect(r.isArray(data.data)).to.be.true;
done();
}).catch(function(err) {
expect(err).to.be.undefined;
done();
});
});
});