Skip to content

Commit

Permalink
feat: add duviri choices (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno authored Sep 18, 2023
1 parent a94a78d commit e97ee37
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 45 deletions.
4 changes: 4 additions & 0 deletions lib/WorldState.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const CambionCycle = require('./models/CambionCycle');
const SteelPathOffering = require('./models/SteelPathOffering');
const Dependency = require('./supporting/Dependency'); // eslint-disable-line no-unused-vars
const DuviriCycle = require('./models/DuviriCycle');
const DuviriChoice = require('./supporting/DuviriChoice');

// needed for type declarations
const MarkdownSettings = require('./supporting/MarkdownSettings');
Expand Down Expand Up @@ -74,6 +75,7 @@ const defaultDeps = {
mdConfig: new MarkdownSettings(),
locale: 'en',
logger: console,
DuviriChoice,
};

/**
Expand Down Expand Up @@ -339,6 +341,8 @@ module.exports = class WorldState {
*/
[this.archonHunt] = parseArray(deps.Sortie, data.LiteSorties, deps);

deps.duviriChoices = parseArray(deps.DuviriChoice, data.EndlessXpChoices, deps);

this.duviriCycle = new DuviriCycle(deps);
}
};
6 changes: 5 additions & 1 deletion lib/models/DuviriCycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const getStageInfo = () => {
* @extends {WorldstateObject}
*/
class DuviriCycle extends WorldstateObject {
constructor({ timeDate, translator }) {
constructor({ timeDate, translator, duviriChoices }) {
super({ _id: { $oid: 'duviriCycle0' } }, { timeDate, translator });
const { activation, expiry, state } = getStageInfo();

Expand All @@ -45,6 +45,10 @@ class DuviriCycle extends WorldstateObject {
* @type {string}
*/
this.state = state;
/**
* Choice options for this Cycle
*/
this.choices = duviriChoices;

this.id = `duviriCycle${this.state}${this.expiry.getTime()}`;
}
Expand Down
20 changes: 20 additions & 0 deletions lib/supporting/DuviriChoice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

/**
* Single category of duviri choices
*/
class DuviriChoice {
constructor(data) {
switch (data.Category) {
case 'EXC_NORMAL':
this.category = 'normal';
break;
case 'EXC_HARD':
this.category = 'hard';
}
this.categoryKey = data.Category;
this.choices = data.Choices;
}
}

module.exports = DuviriChoice;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"scripts": {
"test": "nyc mocha",
"test:integration": "npm run test -- -g 'should parse live worldstate data'",
"test:integration": "npm run test -- -g 'should parse live pc worldstate data'",
"printcov": "nyc report",
"coverage": "npm test && nyc report --reporter=text-lcov | coveralls",
"build-docs": "jsdoc -c jsdoc-config.json -d docs",
Expand Down
76 changes: 33 additions & 43 deletions test/integration/integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,44 @@ const logger = {
log: () => {},
};

const { expect } = chai;
chai.should();
chai.use(sinonChai);

const WorldState = require('../../lib/WorldState');

describe('WorldState (integration)', () => {
describe('#constructor()', async () => {
await Promise.all(
// no more other console worldstates.....
['pc'].map(async function (platform) {
it(`should parse live ${platform} worldstate data`, async function () {
this.timeout = 10000; // allow 10 seconds to parse the worldstate

const { kuvaData, ws } = await fetch('https://10o.io/arbitrations.json')
.then((res) => res.json())
.then(async (semlar) => ({
kuvaData: semlar,
ws: await fetch('https://content.warframe.com/dynamic/worldState.php').then((res) => res.text()),
}));

let wsl;
(() => {
try {
// once without kuva data
wsl = new WorldState(ws, { logger, locale: 'en' });
wsl = new WorldState(ws, { logger, locale: 'en', kuvaData });
} catch (e) {
console.error(e); // eslint-disable-line no-console
throw e;
}
}).should.not.throw();

wsl &&
wsl.news &&
wsl.news.forEach((article) => {
if (article.message.toLowerCase().includes('stream')) {
article.should.include({ stream: true });
}
});
/* Easy debugging! */
if (process.env.CI) {
return fs.writeFile(
path.resolve(`./data.${platform}.json`),
JSON.stringify(wsl.syndicateMissions.find((m) => m.syndicateKey === 'Ostrons'))
);
}
});
})
);
it(`should parse live pc worldstate data`, async function () {
this.timeout = 10000; // allow 10 seconds to parse the worldstate
const kuvaData = await fetch('https://10o.io/arbitrations.json').then((res) => res.json());
const ws = await fetch('https://content.warframe.com/dynamic/worldState.php').then((res) => res.text());

let wsl;
(() => {
try {
// once without kuva data
wsl = new WorldState(ws, { logger, locale: 'en' });
wsl = new WorldState(ws, { logger, locale: 'en', kuvaData });
} catch (e) {
console.error(e); // eslint-disable-line no-console
throw e;
}
}).should.not.throw();

expect(wsl.news).to.exist;
wsl?.news?.forEach((article) => {
if (article.message.toLowerCase().includes('stream')) {
article.should.include({ stream: true });
}
});
expect(wsl?.duviriCycle).to.exist;
wsl?.duviriCycle?.choices.should.have.length.gte(2);
/* Easy debugging! */
if (process.env.CI) {
return fs.writeFile(
path.resolve(`./data.pc.json`),
JSON.stringify(wsl.syndicateMissions.find((m) => m.syndicateKey === 'Ostrons'))
);
}
});
});

0 comments on commit e97ee37

Please sign in to comment.