Update tests to assert against translation strings
This commit is contained in:
@@ -2,6 +2,7 @@ import {
|
||||
createAndPopulateGroup,
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../helpers/api.helper';
|
||||
import {
|
||||
find,
|
||||
@@ -148,7 +149,7 @@ describe('GET /groups/:id', () => {
|
||||
return expect(api.get(`/groups/${createdGroup._id}`))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
text: 'Group not found or you don\'t have access.',
|
||||
text: t('messageGroupNotFound'),
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -178,7 +179,7 @@ describe('GET /groups/:id', () => {
|
||||
return expect(api.get(`/groups/${createdGroup._id}`))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
text: 'Group not found or you don\'t have access.',
|
||||
text: t('messageGroupNotFound'),
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -227,7 +228,7 @@ describe('GET /groups/:id', () => {
|
||||
return expect(api.get('/groups/group-that-does-not-exist'))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
text: 'Group not found or you don\'t have access.',
|
||||
text: t('messageGroupNotFound'),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
generateGroup,
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../helpers/api.helper';
|
||||
|
||||
describe('POST /groups', () => {
|
||||
@@ -82,7 +83,7 @@ describe('POST /groups', () => {
|
||||
});
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 400,
|
||||
text: 'Already in a party, try refreshing.',
|
||||
text: t('messageGroupAlreadyInParty'),
|
||||
});
|
||||
})
|
||||
|
||||
@@ -119,11 +120,10 @@ describe('POST /groups', () => {
|
||||
});
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
text: 'Not enough gems!',
|
||||
text: t('messageInsufficientGems'),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('can create a public guild', () => {
|
||||
return expect(api.post('/groups', {
|
||||
type: 'guild',
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
generateGroup,
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../helpers/api.helper';
|
||||
|
||||
describe('POST /groups/:id', () => {
|
||||
@@ -34,7 +35,7 @@ describe('POST /groups/:id', () => {
|
||||
name: 'Change'
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
text: 'Only the group leader can update the group!',
|
||||
text: t('messageGroupOnlyLeaderCanUpdate'),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
createAndPopulateGroup,
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../helpers/api.helper';
|
||||
import { each, find } from 'lodash';
|
||||
|
||||
@@ -75,7 +76,7 @@ describe('POST /groups/:id/join', () => {
|
||||
return api.get(`/groups/${group._id}`);
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
text: 'Can\'t join a group you\'re not invited to.',
|
||||
text: t('messageGroupRequiresInvite'),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
generateGroup,
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../helpers/api.helper';
|
||||
import { find } from 'lodash';
|
||||
|
||||
@@ -88,7 +89,7 @@ describe('POST /groups/:id/leave', () => {
|
||||
return api.get(`/groups/${group._id}`);
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
text: 'Group not found or you don\'t have access.',
|
||||
text: t('messageGroupNotFound'),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
generateGroup,
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../helpers/api.helper';
|
||||
|
||||
describe('POST /groups/:id/removeMember', () => {
|
||||
@@ -40,7 +41,7 @@ describe('POST /groups/:id/removeMember', () => {
|
||||
uuid: leader._id,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
text: 'You cannot remove yourself!',
|
||||
text: t('messageGroupCannotRemoveSelf'),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../helpers/api.helper';
|
||||
import {v4 as generateRandomUserName} from 'uuid';
|
||||
|
||||
@@ -39,7 +40,55 @@ describe('POST /register', () => {
|
||||
confirmPassword: confirmPassword,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
text: ':password and :confirmPassword don\'t match',
|
||||
text: t('messageAuthPasswordMustMatch'),
|
||||
});
|
||||
});
|
||||
|
||||
it('requires a username', () => {
|
||||
let api = requester();
|
||||
let email = `${generateRandomUserName()}@example.com`;
|
||||
let password = 'password';
|
||||
let confirmPassword = 'password';
|
||||
|
||||
return expect(api.post('/register', {
|
||||
email: email,
|
||||
password: password,
|
||||
confirmPassword: confirmPassword,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
text: t('messageAuthCredentialsRequired'),
|
||||
});
|
||||
});
|
||||
|
||||
it('requires an email', () => {
|
||||
let api = requester();
|
||||
let username = generateRandomUserName();
|
||||
let password = 'password';
|
||||
let confirmPassword = 'password';
|
||||
|
||||
return expect(api.post('/register', {
|
||||
username: username,
|
||||
password: password,
|
||||
confirmPassword: confirmPassword,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
text: t('messageAuthCredentialsRequired'),
|
||||
});
|
||||
});
|
||||
|
||||
it('requires a password', () => {
|
||||
let api = requester();
|
||||
let username = generateRandomUserName();
|
||||
let email = `${username}@example.com`;
|
||||
let confirmPassword = 'password';
|
||||
|
||||
return expect(api.post('/register', {
|
||||
username: username,
|
||||
email: email,
|
||||
confirmPassword: confirmPassword,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
text: t('messageAuthCredentialsRequired'),
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -68,7 +117,7 @@ describe('POST /register', () => {
|
||||
confirmPassword: password,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
text: 'Username already taken',
|
||||
text: t('messageAuthUsernameTaken'),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -84,7 +133,7 @@ describe('POST /register', () => {
|
||||
confirmPassword: password,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
text: 'Email already taken',
|
||||
text: t('messageAuthEmailTaken'),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../helpers/api.helper';
|
||||
|
||||
describe('DELETE /user', () => {
|
||||
@@ -17,10 +18,14 @@ describe('DELETE /user', () => {
|
||||
return api.get('/user');
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
text: 'No user found.',
|
||||
text: t('messageAuthNoUserFound'),
|
||||
});
|
||||
});
|
||||
|
||||
context('user has active subscription', () => {
|
||||
it('does not delete account');
|
||||
});
|
||||
|
||||
context('user in solo group', () => {
|
||||
|
||||
it('deletes party when user is the only member');
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../helpers/api.helper';
|
||||
|
||||
describe('GET /user/tags/id', () => {
|
||||
@@ -22,7 +23,7 @@ describe('GET /user/tags/id', () => {
|
||||
return expect(api.get('/user/tags/not-an-id'))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
text: 'Tag not found.'
|
||||
text: t('messageTagNotFound'),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../helpers/api.helper';
|
||||
|
||||
import { each } from 'lodash';
|
||||
@@ -15,7 +16,7 @@ describe('PUT /user', () => {
|
||||
});
|
||||
});
|
||||
|
||||
context('allowed paths', () => {
|
||||
context('allowed operations', () => {
|
||||
it('updates the user', () => {
|
||||
return api.put('/user', {
|
||||
'profile.name' : 'Frodo',
|
||||
@@ -29,8 +30,8 @@ describe('PUT /user', () => {
|
||||
});
|
||||
});
|
||||
|
||||
context('top level protected paths', () => {
|
||||
let protectedPaths = {
|
||||
context('top level protected operations', () => {
|
||||
let protectedOperations = {
|
||||
'gem balance': {balance: 100},
|
||||
'auth': {'auth.blocked': true, 'auth.timestamps.created': new Date()},
|
||||
'contributor': {'contributor.level': 9, 'contributor.admin': true, 'contributor.text': 'some text'},
|
||||
@@ -40,11 +41,11 @@ describe('PUT /user', () => {
|
||||
'tasks': {todos: [], habits: [], dailys: [], rewards: []},
|
||||
};
|
||||
|
||||
each(protectedPaths, (data, testName) => {
|
||||
each(protectedOperations, (data, testName) => {
|
||||
it(`does not allow updating ${testName}`, () => {
|
||||
let errorText = [];
|
||||
each(data, (value, path) => {
|
||||
errorText.push(`path \`${path}\` was not saved, as it's a protected path.`);
|
||||
each(data, (value, operation) => {
|
||||
errorText.push(t('messageUserOperationProtected', { operation: operation }));
|
||||
});
|
||||
return expect(api.put('/user', data)).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
@@ -54,16 +55,16 @@ describe('PUT /user', () => {
|
||||
});
|
||||
});
|
||||
|
||||
context('sub-level protected paths', () => {
|
||||
let protectedPaths = {
|
||||
context('sub-level protected operations', () => {
|
||||
let protectedOperations = {
|
||||
'class stat': {'stats.class': 'wizard'},
|
||||
};
|
||||
|
||||
each(protectedPaths, (data, testName) => {
|
||||
each(protectedOperations, (data, testName) => {
|
||||
it(`does not allow updating ${testName}`, () => {
|
||||
let errorText = [];
|
||||
each(data, (value, path) => {
|
||||
errorText.push(`path \`${path}\` was not saved, as it's a protected path.`);
|
||||
each(data, (value, operation) => {
|
||||
errorText.push(t('messageUserOperationProtected', { operation: operation }));
|
||||
});
|
||||
return expect(api.put('/user', data)).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../../helpers/api.helper';
|
||||
|
||||
import { each } from 'lodash';
|
||||
@@ -49,7 +50,7 @@ describe('POST /user/batch-update', () => {
|
||||
{op: operation},
|
||||
])).to.eventually.be.rejected.and.eql({
|
||||
code: 500,
|
||||
text: `${operation} operation not found`,
|
||||
text: t('messageUserOperationNotFound', { operation: operation}),
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -61,7 +62,7 @@ describe('POST /user/batch-update', () => {
|
||||
{op: 'aNotRealOperation'},
|
||||
])).to.eventually.be.rejected.and.eql({
|
||||
code: 500,
|
||||
text: 'aNotRealOperation operation not found',
|
||||
text: t('messageUserOperationNotFound', { operation: 'aNotRealOperation' }),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../../helpers/api.helper';
|
||||
|
||||
describe('DELETE /user/tasks/:id', () => {
|
||||
@@ -20,7 +21,7 @@ describe('DELETE /user/tasks/:id', () => {
|
||||
return api.get(`/user/tasks/${task.id}`);
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
text: 'No task found.',
|
||||
text: t('messageTaskNotFound'),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -28,7 +29,7 @@ describe('DELETE /user/tasks/:id', () => {
|
||||
return expect(api.del('/user/tasks/task-that-does-not-exist'))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
text: 'Task not found.',
|
||||
text: t('messageTaskNotFound'),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../../helpers/api.helper';
|
||||
|
||||
describe('GET /user/tasks/', () => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../../helpers/api.helper';
|
||||
|
||||
describe('GET /user/tasks/:id', () => {
|
||||
@@ -28,7 +29,7 @@ describe('GET /user/tasks/:id', () => {
|
||||
return expect(api.get('/user/tasks/task-that-does-not-exist'))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
text: 'No task found.',
|
||||
text: t('messageTaskNotFound'),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -38,7 +39,7 @@ describe('GET /user/tasks/:id', () => {
|
||||
return api.get(`/user/tasks/${otherUsersTask.id}`);
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
text: 'No task found.',
|
||||
text: t('messageTaskNotFound'),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../../helpers/api.helper';
|
||||
|
||||
describe('POST /user/tasks', () => {
|
||||
@@ -46,7 +47,7 @@ describe('POST /user/tasks', () => {
|
||||
id: todo.id,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 409,
|
||||
text: 'A task with that ID already exists.',
|
||||
text: t('messageDuplicateTaskID'),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../../helpers/api.helper';
|
||||
|
||||
describe('PUT /user/tasks/:id', () => {
|
||||
|
||||
@@ -7,6 +7,9 @@ import {
|
||||
import {MongoClient as mongo} from 'mongodb';
|
||||
import {v4 as generateUUID} from 'uuid';
|
||||
import superagent from 'superagent';
|
||||
import i18n from '../../common/script/src/i18n';
|
||||
require('coffee-script');
|
||||
i18n.translations = require('../../website/src/i18n.js').translations;
|
||||
|
||||
const API_TEST_SERVER_PORT = 3003;
|
||||
|
||||
@@ -22,6 +25,22 @@ export function requester(user={}) {
|
||||
}
|
||||
};
|
||||
|
||||
// Use this to verify error messages returned by the server
|
||||
// That way, if the translated string changes, the test
|
||||
// will not break. NOTE: it checks agains errors with string as well.
|
||||
export function translate(key, variables) {
|
||||
const STRING_ERROR_MSG = 'Error processing the string. Please see Help > Report a Bug.';
|
||||
const STRING_DOES_NOT_EXIST_MSG = /^String '.*' not found.$/;
|
||||
|
||||
let translatedString = i18n.t(key, variables);
|
||||
|
||||
expect(translatedString).to.not.be.empty;
|
||||
expect(translatedString).to.not.eql(STRING_ERROR_MSG);
|
||||
expect(translatedString).to.not.match(STRING_DOES_NOT_EXIST_MSG);
|
||||
|
||||
return translatedString;
|
||||
};
|
||||
|
||||
// Creates a new user and returns it
|
||||
// If you need the user to have specific requirements,
|
||||
// such as a balance > 0, just pass in the adjustment
|
||||
|
||||
Reference in New Issue
Block a user