Skip to content

Commit

Permalink
fix: modified sentient outpost regex to only target the sfn key-val…
Browse files Browse the repository at this point in the history
…ue (#530)
  • Loading branch information
SlayerOrnstein authored Jun 10, 2024
1 parent 82736b4 commit 2b05c87
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/models/SentientOutpost.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export default class SentientOutpost {
#node;
constructor(data, { locale, sentientData, logger }) {
if (!data) data = '{"sfn":000}';
[this.#node] = data.match(/\d{3}/g) || ['000'];
const json = JSON.parse(data);
this.#node = json.sfn || '000';
const id = `CrewBattleNode${this.#node}`;
/* istanbul ignore if */
if (this.#node === '000') {
Expand Down
19 changes: 19 additions & 0 deletions test/data/Tmp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const tmp = JSON.stringify({
prisbegin: '1687363200',
prisend: '1688572800',
cavabegin: '1690761600',
PurchasePlatformLockEnabled: true,
lqo9: {
mt: ['Survival', 'Extermination', 'Alchemy'],
mv: ['UnpoweredCapsules', 'FortifiedFoes', 'AlchemicalShields'],
c: [
['RegeneratingEnemies', 'PointBlank'],
['Quicksand', 'EMPBlackHole'],
['Deflectors', 'AcceleratedEnemies'],
],
fv: ['ContactDamage', 'Withering', 'Gearless', 'Exhaustion'],
},
sfn: 554,
});

export default tmp;
27 changes: 27 additions & 0 deletions test/unit/sentientOutpost.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as chai from 'chai';
import sinonChai from 'sinon-chai';

import SentientOutpost from '../../lib/models/SentientOutpost.js';
import data from '../data/Tmp.js';

chai.should();
chai.use(sinonChai);

describe('SentientOutpost', function () {
describe('#constructor()', function () {
it('should be able to handle some raw data', () => {
const outpost = new SentientOutpost(data, { locale: 'en', logger: console });

outpost.id.should.equal('CrewBattleNode554:true');
outpost.mission.node.should.equal('H-2 Cloud (Veil)');
});
it('should throw TypeError when called with no argument or an invalid argument', function () {
(() => {
new SentientOutpost();
}).should.throw(TypeError);
(() => {
new SentientOutpost({});
}).should.throw(TypeError);
});
});
});

0 comments on commit 2b05c87

Please sign in to comment.