mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
tests(api): bring in await format tests
This commit is contained in:
@@ -8,32 +8,36 @@ import { each } from 'lodash';
|
||||
|
||||
describe('POST /user/auth/local/register', () => {
|
||||
context('username and email are free', () => {
|
||||
it('registers a new user', () => {
|
||||
let api = requester();
|
||||
let api;
|
||||
|
||||
beforeEach(async () => {
|
||||
api = requester();
|
||||
});
|
||||
|
||||
it('registers a new user', async () => {
|
||||
let username = generateRandomUserName();
|
||||
let email = `${username}@example.com`;
|
||||
let password = 'password';
|
||||
|
||||
return api.post('/user/auth/local/register', {
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
confirmPassword: password,
|
||||
}).then((user) => {
|
||||
expect(user._id).to.exist;
|
||||
expect(user.apiToken).to.exist;
|
||||
expect(user.auth.local.username).to.eql(username);
|
||||
});
|
||||
|
||||
expect(user._id).to.exist;
|
||||
expect(user.apiToken).to.exist;
|
||||
expect(user.auth.local.username).to.eql(username);
|
||||
});
|
||||
|
||||
it('requires password and confirmPassword to match', () => {
|
||||
let api = requester();
|
||||
it('requires password and confirmPassword to match', async () => {
|
||||
let username = generateRandomUserName();
|
||||
let email = `${username}@example.com`;
|
||||
let password = 'password';
|
||||
let confirmPassword = 'not password';
|
||||
|
||||
return expect(api.post('/user/auth/local/register', {
|
||||
await expect(api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
@@ -45,13 +49,12 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('requires a username', () => {
|
||||
let api = requester();
|
||||
it('requires a username', async () => {
|
||||
let email = `${generateRandomUserName()}@example.com`;
|
||||
let password = 'password';
|
||||
let confirmPassword = 'password';
|
||||
|
||||
return expect(api.post('/user/auth/local/register', {
|
||||
await expect(api.post('/user/auth/local/register', {
|
||||
email,
|
||||
password,
|
||||
confirmPassword,
|
||||
@@ -62,12 +65,11 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('requires an email', () => {
|
||||
let api = requester();
|
||||
it('requires an email', async () => {
|
||||
let username = generateRandomUserName();
|
||||
let password = 'password';
|
||||
|
||||
return expect(api.post('/user/auth/local/register', {
|
||||
await expect(api.post('/user/auth/local/register', {
|
||||
username,
|
||||
password,
|
||||
confirmPassword: password,
|
||||
@@ -78,13 +80,12 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('requires a valid email', () => {
|
||||
let api = requester();
|
||||
it('requires a valid email', async () => {
|
||||
let username = generateRandomUserName();
|
||||
let email = 'notanemail@sdf';
|
||||
let password = 'password';
|
||||
|
||||
return expect(api.post('/user/auth/local/register', {
|
||||
await expect(api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
@@ -96,13 +97,12 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('requires a password', () => {
|
||||
let api = requester();
|
||||
it('requires a password', async () => {
|
||||
let username = generateRandomUserName();
|
||||
let email = `${username}@example.com`;
|
||||
let confirmPassword = 'password';
|
||||
|
||||
return expect(api.post('/user/auth/local/register', {
|
||||
await expect(api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
confirmPassword,
|
||||
@@ -115,11 +115,13 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
context('login is already taken', () => {
|
||||
let username, email;
|
||||
let username, email, api;
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
api = requester();
|
||||
username = generateRandomUserName();
|
||||
email = `${username}@example.com`;
|
||||
|
||||
return generateUser({
|
||||
'auth.local.username': username,
|
||||
'auth.local.lowerCaseUsername': username,
|
||||
@@ -127,12 +129,11 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects if username is already taken', () => {
|
||||
let api = requester();
|
||||
it('rejects if username is already taken', async () => {
|
||||
let uniqueEmail = `${generateRandomUserName()}@exampe.com`;
|
||||
let password = 'password';
|
||||
|
||||
return expect(api.post('/user/auth/local/register', {
|
||||
await expect(api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email: uniqueEmail,
|
||||
password,
|
||||
@@ -144,12 +145,11 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects if email is already taken', () => {
|
||||
let api = requester();
|
||||
it('rejects if email is already taken', async () => {
|
||||
let uniqueUsername = generateRandomUserName();
|
||||
let password = 'password';
|
||||
|
||||
return expect(api.post('/user/auth/local/register', {
|
||||
await expect(api.post('/user/auth/local/register', {
|
||||
username: uniqueUsername,
|
||||
email,
|
||||
password,
|
||||
@@ -172,44 +172,44 @@ describe('POST /user/auth/local/register', () => {
|
||||
password = 'password';
|
||||
});
|
||||
|
||||
it('sets all site tour values to -2 (already seen)', () => {
|
||||
return api.post('/user/auth/local/register', {
|
||||
it('sets all site tour values to -2 (already seen)', async () => {
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
confirmPassword: password,
|
||||
}).then((user) => {
|
||||
expect(user.flags.tour).to.not.be.empty;
|
||||
});
|
||||
|
||||
each(user.flags.tour, (value) => {
|
||||
expect(value).to.eql(-2);
|
||||
});
|
||||
expect(user.flags.tour).to.not.be.empty;
|
||||
|
||||
each(user.flags.tour, (value) => {
|
||||
expect(value).to.eql(-2);
|
||||
});
|
||||
});
|
||||
|
||||
it('populates user with default todos, not no other task types', () => {
|
||||
return api.post('/user/auth/local/register', {
|
||||
it('populates user with default todos, not no other task types', async () => {
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
confirmPassword: password,
|
||||
}).then((user) => {
|
||||
expect(user.tasksOrder.todos).to.not.be.empty;
|
||||
expect(user.tasksOrder.dailys).to.be.empty;
|
||||
expect(user.tasksOrder.habits).to.be.empty;
|
||||
expect(user.tasksOrder.rewards).to.be.empty;
|
||||
});
|
||||
|
||||
expect(user.tasksOrder.todos).to.not.be.empty;
|
||||
expect(user.tasksOrder.dailys).to.be.empty;
|
||||
expect(user.tasksOrder.habits).to.be.empty;
|
||||
expect(user.tasksOrder.rewards).to.be.empty;
|
||||
});
|
||||
|
||||
it('populates user with default tags', () => {
|
||||
return api.post('/user/auth/local/register', {
|
||||
it('populates user with default tags', async () => {
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
confirmPassword: password,
|
||||
}).then((user) => {
|
||||
expect(user.tags).to.not.be.empty;
|
||||
});
|
||||
|
||||
expect(user.tags).to.not.be.empty;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -223,44 +223,44 @@ describe('POST /user/auth/local/register', () => {
|
||||
password = 'password';
|
||||
});
|
||||
|
||||
it('sets all common tutorial flags to true', () => {
|
||||
return api.post('/user/auth/local/register', {
|
||||
it('sets all common tutorial flags to true', async () => {
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
confirmPassword: password,
|
||||
}).then((user) => {
|
||||
expect(user.flags.tour).to.not.be.empty;
|
||||
});
|
||||
|
||||
each(user.flags.tutorial.common, (value) => {
|
||||
expect(value).to.eql(true);
|
||||
});
|
||||
expect(user.flags.tour).to.not.be.empty;
|
||||
|
||||
each(user.flags.tutorial.common, (value) => {
|
||||
expect(value).to.eql(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('populates user with default todos, habits, and rewards', () => {
|
||||
return api.post('/user/auth/local/register', {
|
||||
it('populates user with default todos, habits, and rewards', async () => {
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
confirmPassword: password,
|
||||
}).then((user) => {
|
||||
expect(user.tasksOrder.todos).to.not.be.empty;
|
||||
expect(user.tasksOrder.dailys).to.be.empty;
|
||||
expect(user.tasksOrder.habits).to.not.be.empty;
|
||||
expect(user.tasksOrder.rewards).to.not.be.empty;
|
||||
});
|
||||
|
||||
expect(user.tasksOrder.todos).to.not.be.empty;
|
||||
expect(user.tasksOrder.dailys).to.be.empty;
|
||||
expect(user.tasksOrder.habits).to.not.be.empty;
|
||||
expect(user.tasksOrder.rewards).to.not.be.empty;
|
||||
});
|
||||
|
||||
it('populates user with default tags', () => {
|
||||
return api.post('/user/auth/local/register', {
|
||||
it('populates user with default tags', async () => {
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
confirmPassword: password,
|
||||
}).then((user) => {
|
||||
expect(user.tags).to.not.be.empty;
|
||||
});
|
||||
|
||||
expect(user.tags).to.not.be.empty;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user