test fixes

This commit is contained in:
Phillip Thelen
2024-05-14 11:07:15 +02:00
parent 592c320d1d
commit 6591f6780c
4 changed files with 41 additions and 26 deletions

View File

@@ -38,22 +38,22 @@ describe('armoire', () => {
const items = makeArmoireIitemList(); const items = makeArmoireIitemList();
expect(items.length).to.equal(377); expect(items.length).to.equal(377);
forEach(items, item => { forEach(items, item => {
expect(item.released).to.be.true; expect(item.released, item.key).to.be.true;
}); });
}); });
it('released gear has all required properties', async () => { it('released gear has all required properties', async () => {
clock = sinon.useFakeTimers(new Date('2024-05-08')); clock = sinon.useFakeTimers(new Date('2024-05-08'));
const items = makeArmoireIitemList(); const items = makeArmoireIitemList();
expect(items.length).to.equal(392); expect(items.length).to.equal(396);
forEach(items, item => { forEach(items, item => {
if (item.set !== undefined) { if (item.set !== undefined) {
expect(item.set).to.be.a('string'); expect(item.set, item.key).to.be.a('string');
expect(item.set).to.not.be.empty; expect(item.set, item.key).to.not.be.empty;
} }
expectValidTranslationString(item.text); expectValidTranslationString(item.text);
expect(item.released).to.be.a('boolean'); expect(item.released, item.key).to.be.a('boolean');
expect(item.value).to.be.a('number'); expect(item.value, item.key).to.be.a('number');
}); });
}); });

View File

@@ -4,6 +4,8 @@ import {
expectValidTranslationString, expectValidTranslationString,
} from '../helpers/content.helper'; } from '../helpers/content.helper';
import { CLASSES } from '../../website/common/script/content/constants';
import gearData from '../../website/common/script/content/gear'; import gearData from '../../website/common/script/content/gear';
import * as backerGear from '../../website/common/script/content/gear/sets/special/special-backer'; import * as backerGear from '../../website/common/script/content/gear/sets/special/special-backer';
import * as contributorGear from '../../website/common/script/content/gear/sets/special/special-contributor'; import * as contributorGear from '../../website/common/script/content/gear/sets/special/special-contributor';
@@ -17,35 +19,48 @@ describe('Gear', () => {
context(`${klass} ${gearType}s`, () => { context(`${klass} ${gearType}s`, () => {
it('have a value of at least 0 for each stat', () => { it('have a value of at least 0 for each stat', () => {
each(items, gear => { each(items, gear => {
expect(gear.con).to.be.at.least(0); expect(gear.con, gear.key).to.be.at.least(0);
expect(gear.int).to.be.at.least(0); expect(gear.int, gear.key).to.be.at.least(0);
expect(gear.per).to.be.at.least(0); expect(gear.per, gear.key).to.be.at.least(0);
expect(gear.str).to.be.at.least(0); expect(gear.str, gear.key).to.be.at.least(0);
}); });
}); });
it('have a purchase value of at least 0', () => { it('have a purchase value of at least 0', () => {
each(items, gear => { each(items, gear => {
expect(gear.value).to.be.at.least(0); expect(gear.value, gear.key).to.be.at.least(0);
}); });
}); });
it('has a canBuy function', () => { it('has a canBuy function', () => {
each(items, gear => { each(items, gear => {
expect(gear.canBuy).to.be.a('function'); expect(gear.canBuy, gear.key).to.be.a('function');
}); });
}); });
it('have valid translation strings for text and notes', () => { it('have valid translation strings for text and notes', () => {
each(items, gear => { each(items, gear => {
expectValidTranslationString(gear.text); expectValidTranslationString(gear.text, gear.key);
expectValidTranslationString(gear.notes); expectValidTranslationString(gear.notes, gear.key);
}); });
}); });
it('has a set attribue', () => { it('has a set attribue', () => {
each(items, gear => { each(items, gear => {
expect(gear.set).to.exist; expect(gear.set, gear.key).to.exist;
});
});
it('has a valid value for klass or specialClass', () => {
const validClassValues = CLASSES + ['base', 'mystery', 'armoire'];
each(items, gear => {
const field = gear.klass === 'special' ? gear.specialClass : gear.klass;
if (gear.klass === 'special' && field === undefined) {
// some special gear doesn't have a klass
return;
}
expect(field, gear.key).to.exist;
expect(validClassValues, gear.key).to.include(field);
}); });
}); });
}); });

View File

@@ -96,31 +96,31 @@ describe('Content Schedule', () => {
it('sets the end date if its in the same month', () => { it('sets the end date if its in the same month', () => {
const date = new Date('2024-04-03'); const date = new Date('2024-04-03');
const matchers = getAllScheduleMatchingGroups(date); const matchers = getAllScheduleMatchingGroups(date);
expect(matchers.backgrounds.end).to.eql(moment('2024-04-07').toDate()); expect(matchers.backgrounds.end).to.eql(moment.utc('2024-04-07').toDate());
}); });
it('sets the end date if its in the next day', () => { it('sets the end date if its in the next day', () => {
const date = new Date('2024-05-06T14:00:00.000Z'); const date = new Date('2024-05-06T14:00:00.000Z');
const matchers = getAllScheduleMatchingGroups(date); const matchers = getAllScheduleMatchingGroups(date);
expect(matchers.backgrounds.end).to.eql(moment('2024-05-07').toDate()); expect(matchers.backgrounds.end).to.eql(moment.utc('2024-05-07').toDate());
}); });
it('sets the end date if its on the release day', () => { it('sets the end date if its on the release day', () => {
const date = new Date('2024-05-07'); const date = new Date('2024-05-07');
const matchers = getAllScheduleMatchingGroups(date); const matchers = getAllScheduleMatchingGroups(date);
expect(matchers.backgrounds.end).to.eql(moment('2024-06-07').toDate()); expect(matchers.backgrounds.end).to.eql(moment.utc('2024-06-07').toDate());
}); });
it('sets the end date if its next month', () => { it('sets the end date if its next month', () => {
const date = new Date('2024-05-20T01:00:00.000Z'); const date = new Date('2024-05-20T01:00:00.000Z');
const matchers = getAllScheduleMatchingGroups(date); const matchers = getAllScheduleMatchingGroups(date);
expect(matchers.backgrounds.end).to.eql(moment('2024-06-07').toDate()); expect(matchers.backgrounds.end).to.eql(moment.utc('2024-06-07').toDate());
}); });
it('sets the end date for a gala', () => { it('sets the end date for a gala', () => {
const date = new Date('2024-05-20'); const date = new Date('2024-05-20');
const matchers = getAllScheduleMatchingGroups(date); const matchers = getAllScheduleMatchingGroups(date);
expect(matchers.seasonalGear.end).to.eql(moment('2024-06-21').toDate()); expect(matchers.seasonalGear.end).to.eql(moment.utc('2024-06-21').toDate());
}); });
it('contains content for repeating events', () => { it('contains content for repeating events', () => {

View File

@@ -7,13 +7,13 @@ i18n.translations = translations;
export const STRING_ERROR_MSG = /^Error processing the string ".*". Please see Help > Report a Bug.$/; export const STRING_ERROR_MSG = /^Error processing the string ".*". Please see Help > Report a Bug.$/;
export const STRING_DOES_NOT_EXIST_MSG = /^String '.*' not found.$/; export const STRING_DOES_NOT_EXIST_MSG = /^String '.*' not found.$/;
export function expectValidTranslationString (attribute) { export function expectValidTranslationString (attribute, contextKey) {
expect(attribute).to.be.a('function'); expect(attribute, contextKey).to.be.a('function');
const translatedString = attribute(); const translatedString = attribute();
expect(translatedString.trim()).to.not.be.empty; expect(translatedString.trim(), contextKey).to.not.be.empty;
expect(translatedString).to.not.contain('function func(lang)'); expect(translatedString, contextKey).to.not.contain('function func(lang)');
expect(translatedString).to.not.eql(STRING_ERROR_MSG); expect(translatedString, contextKey).to.not.eql(STRING_ERROR_MSG);
expect(translatedString).to.not.match(STRING_DOES_NOT_EXIST_MSG); expect(translatedString, contextKey).to.not.match(STRING_DOES_NOT_EXIST_MSG);
} }