moving developer-only strings to api/common messages (#10258)

* move translatable string to apiMessages

* use apiMessages instead of res.t for groupIdRequired / keepOrRemove

* move pageMustBeNumber to apiMessages

* change apimessages

* move missingKeyParam to apiMessages

* move more strings to apiMessages

* fix lint

* revert lodash imports to fix tests

* fix webhook test

* fix test

* rollback key change of `keepOrRemove`

* remove unneeded `req.language` param

*  extract more messages from i18n

* add missing `missingTypeParam` message

* Split api- and commonMessages

* fix test

* fix sanity

* merge messages to an object, rename commonMessage to errorMessage

* apiMessages -> apiError, commonMessages -> errorMessage, extract messages to separate objects

* fix test

* module.exports
This commit is contained in:
negue
2018-05-04 23:00:19 +02:00
committed by Sabe Jones
parent f226b5da07
commit c26696a9eb
65 changed files with 254 additions and 185 deletions
+2 -1
View File
@@ -8,6 +8,7 @@ import {
} from '../../../../website/common/script/libs/errors';
import i18n from '../../../../website/common/script/i18n';
import content from '../../../../website/common/script/content/index';
import errorMessage from '../../../../website/common/script/libs/errorMessage';
describe('shared.ops.buy', () => {
let user;
@@ -40,7 +41,7 @@ describe('shared.ops.buy', () => {
buy(user);
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('missingKeyParam'));
expect(err.message).to.equal(errorMessage('missingKeyParam'));
done();
}
});
+3 -2
View File
@@ -10,6 +10,7 @@ import {
BadRequest, NotAuthorized, NotFound,
} from '../../../../website/common/script/libs/errors';
import i18n from '../../../../website/common/script/i18n';
import errorMessage from '../../../../website/common/script/libs/errorMessage';
function buyGear (user, req, analytics) {
let buyOp = new BuyMarketGearOperation(user, req, analytics);
@@ -190,7 +191,7 @@ describe('shared.ops.buyMarketGear', () => {
buyGear(user);
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('missingKeyParam'));
expect(err.message).to.equal(errorMessage('missingKeyParam'));
done();
}
});
@@ -202,7 +203,7 @@ describe('shared.ops.buyMarketGear', () => {
buyGear(user, {params});
} catch (err) {
expect(err).to.be.an.instanceof(NotFound);
expect(err.message).to.equal(i18n.t('itemNotFound', params));
expect(err.message).to.equal(errorMessage('itemNotFound', params));
done();
}
});
+2 -1
View File
@@ -10,6 +10,7 @@ import {
NotFound,
} from '../../../../website/common/script/libs/errors';
import i18n from '../../../../website/common/script/i18n';
import errorMessage from '../../../../website/common/script/libs/errorMessage';
describe('shared.ops.buyMysterySet', () => {
let user;
@@ -70,7 +71,7 @@ describe('shared.ops.buyMysterySet', () => {
buyMysterySet(user);
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('missingKeyParam'));
expect(err.message).to.equal(errorMessage('missingKeyParam'));
done();
}
});
+3 -2
View File
@@ -8,6 +8,7 @@ import {
NotFound,
} from '../../../../website/common/script/libs/errors';
import i18n from '../../../../website/common/script/i18n';
import errorMessage from '../../../../website/common/script/libs/errorMessage';
describe('shared.ops.buyQuest', () => {
let user;
@@ -106,7 +107,7 @@ describe('shared.ops.buyQuest', () => {
});
} catch (err) {
expect(err).to.be.an.instanceof(NotFound);
expect(err.message).to.equal(i18n.t('questNotFound', {key: 'snarfblatter'}));
expect(err.message).to.equal(errorMessage('questNotFound', {key: 'snarfblatter'}));
expect(user.items.quests).to.eql({});
expect(user.stats.gp).to.equal(9999);
done();
@@ -151,7 +152,7 @@ describe('shared.ops.buyQuest', () => {
buyQuest(user);
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('missingKeyParam'));
expect(err.message).to.equal(errorMessage('missingKeyParam'));
done();
}
});
+3 -2
View File
@@ -9,6 +9,7 @@ import {
generateUser,
} from '../../../helpers/common.helper';
import content from '../../../../website/common/script/content/index';
import errorMessage from '../../../../website/common/script/libs/errorMessage';
describe('shared.ops.buySpecialSpell', () => {
let user;
@@ -28,7 +29,7 @@ describe('shared.ops.buySpecialSpell', () => {
buySpecialSpell(user);
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('missingKeyParam'));
expect(err.message).to.equal(errorMessage('missingKeyParam'));
done();
}
});
@@ -42,7 +43,7 @@ describe('shared.ops.buySpecialSpell', () => {
});
} catch (err) {
expect(err).to.be.an.instanceof(NotFound);
expect(err.message).to.equal(i18n.t('spellNotFound', {spellId: 'notExisting'}));
expect(err.message).to.equal(errorMessage('spellNotFound', {spellId: 'notExisting'}));
done();
}
});
+3 -2
View File
@@ -8,6 +8,7 @@ import content from '../../../../website/common/script/content/index';
import {
generateUser,
} from '../../../helpers/common.helper';
import errorMessage from '../../../../website/common/script/libs/errorMessage';
describe('common.ops.hourglassPurchase', () => {
let user;
@@ -28,7 +29,7 @@ describe('common.ops.hourglassPurchase', () => {
hourglassPurchase(user, {params: {}});
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.eql(i18n.t('missingKeyParam'));
expect(err.message).to.eql(errorMessage('missingKeyParam'));
done();
}
});
@@ -38,7 +39,7 @@ describe('common.ops.hourglassPurchase', () => {
hourglassPurchase(user, {params: {key: 'Base'}});
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.eql(i18n.t('missingTypeParam'));
expect(err.message).to.eql(errorMessage('missingTypeParam'));
done();
}
});
+4 -3
View File
@@ -9,6 +9,7 @@ import i18n from '../../../website/common/script/i18n';
import {
generateUser,
} from '../../helpers/common.helper';
import errorMessage from '../../../website/common/script/libs/errorMessage';
describe('shared.ops.feed', () => {
let user;
@@ -23,7 +24,7 @@ describe('shared.ops.feed', () => {
feed(user);
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('missingPetFoodFeed'));
expect(err.message).to.equal(errorMessage('missingPetFoodFeed'));
done();
}
});
@@ -33,7 +34,7 @@ describe('shared.ops.feed', () => {
feed(user, {params: {pet: 'invalid', food: 'food'}});
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('invalidPetName'));
expect(err.message).to.equal(errorMessage('invalidPetName'));
done();
}
});
@@ -43,7 +44,7 @@ describe('shared.ops.feed', () => {
feed(user, {params: {pet: 'Wolf-Red', food: 'invalid food name'}});
} catch (err) {
expect(err).to.be.an.instanceof(NotFound);
expect(err.message).to.equal(i18n.t('messageFoodNotFound'));
expect(err.message).to.equal(errorMessage('invalidFoodName'));
done();
}
});
+2 -1
View File
@@ -8,6 +8,7 @@ import i18n from '../../../website/common/script/i18n';
import {
generateUser,
} from '../../helpers/common.helper';
import errorMessage from '../../../website/common/script/libs/errorMessage';
describe('shared.ops.hatch', () => {
let user;
@@ -24,7 +25,7 @@ describe('shared.ops.hatch', () => {
hatch(user);
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('missingEggHatchingPotionHatch'));
expect(err.message).to.equal(errorMessage('missingEggHatchingPotion'));
expect(user.items.pets).to.be.empty;
}
});
+2 -1
View File
@@ -7,6 +7,7 @@ import i18n from '../../../../website/common/script/i18n';
import {
generateUser,
} from '../../../helpers/common.helper';
import errorMessage from '../../../../website/common/script/libs/errorMessage';
describe('shared.ops.allocate', () => {
let user;
@@ -22,7 +23,7 @@ describe('shared.ops.allocate', () => {
});
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('invalidAttribute', {attr: 'notValid'}));
expect(err.message).to.equal(errorMessage('invalidAttribute', {attr: 'notValid'}));
done();
}
});
+3 -2
View File
@@ -7,6 +7,7 @@ import i18n from '../../../../website/common/script/i18n';
import {
generateUser,
} from '../../../helpers/common.helper';
import errorMessage from '../../../../website/common/script/libs/errorMessage';
describe('shared.ops.allocateBulk', () => {
let user;
@@ -27,7 +28,7 @@ describe('shared.ops.allocateBulk', () => {
});
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('invalidAttribute', {attr: 'invalid'}));
expect(err.message).to.equal(errorMessage('invalidAttribute', {attr: 'invalid'}));
done();
}
});
@@ -37,7 +38,7 @@ describe('shared.ops.allocateBulk', () => {
allocateBulk(user);
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('statsObjectRequired'));
expect(err.message).to.equal(errorMessage('statsObjectRequired'));
done();
}
});