diff --git a/test/api/v2/register/POST-register.test.js b/test/api/v2/register/POST-register.test.js index 19c9b3e341..e40963830e 100644 --- a/test/api/v2/register/POST-register.test.js +++ b/test/api/v2/register/POST-register.test.js @@ -3,7 +3,8 @@ import { requester, translate as t, } from '../../../helpers/api-integration.helper'; -import {v4 as generateRandomUserName} from 'uuid'; +import { v4 as generateRandomUserName } from 'uuid'; +import { each } from 'lodash'; describe('POST /register', () => { @@ -137,4 +138,106 @@ describe('POST /register', () => { }); }); }); + + context('successful login via api', () => { + let api, username, email, password; + + beforeEach(() => { + api = requester(); + username = generateRandomUserName(); + email = `${username}@example.com`; + password = 'password'; + }); + + it('sets all site tour values to -2 (already seen)', () => { + return api.post('/register', { + username: username, + email: email, + password: password, + confirmPassword: password, + }).then((user) => { + expect(user.flags.tour).to.not.be.empty; + + each(user.flags.tour, (value, attribute) => { + expect(value).to.eql(-2); + }); + }); + }); + + it('populates user with default todos, not no other task types', () => { + return api.post('/register', { + username: username, + email: email, + password: password, + confirmPassword: password, + }).then((user) => { + expect(user.todos).to.not.be.empty; + expect(user.dailys).to.be.empty; + expect(user.habits).to.be.empty; + expect(user.rewards).to.be.empty; + }); + }); + + it('populates user with default tags', () => { + return api.post('/register', { + username: username, + email: email, + password: password, + confirmPassword: password, + }).then((user) => { + expect(user.tags).to.not.be.empty; + }); + }); + }); + + context('successful login with habitica-web header', () => { + let api, username, email, password; + + beforeEach(() => { + api = requester({}, {'x-client': 'habitica-web'}); + username = generateRandomUserName(); + email = `${username}@example.com`; + password = 'password'; + }); + + it('sets all common tutorial flags to true', () => { + return api.post('/register', { + username: username, + email: email, + password: password, + confirmPassword: password, + }).then((user) => { + expect(user.flags.tour).to.not.be.empty; + + each(user.flags.tutorial.common, (value, attribute) => { + expect(value).to.eql(true); + }); + }); + }); + + it('populates user with default todos, habits, and rewards', () => { + return api.post('/register', { + username: username, + email: email, + password: password, + confirmPassword: password, + }).then((user) => { + expect(user.todos).to.not.be.empty; + expect(user.dailys).to.be.empty; + expect(user.habits).to.not.be.empty; + expect(user.rewards).to.not.be.empty; + }); + }); + + it('populates user with default tags', () => { + return api.post('/register', { + username: username, + email: email, + password: password, + confirmPassword: password, + }).then((user) => { + expect(user.tags).to.not.be.empty; + }); + }); + }); }); diff --git a/test/api/v2/user/tasks/GET-tasks.test.js b/test/api/v2/user/tasks/GET-tasks.test.js index 6c70bdd554..89492b717b 100644 --- a/test/api/v2/user/tasks/GET-tasks.test.js +++ b/test/api/v2/user/tasks/GET-tasks.test.js @@ -8,7 +8,14 @@ describe('GET /user/tasks/', () => { let api, user; beforeEach(() => { - return generateUser().then((_user) => { + return generateUser({ + dailys: [ + {text: 'daily', type: 'daily'}, + {text: 'daily', type: 'daily'}, + {text: 'daily', type: 'daily'}, + {text: 'daily', type: 'daily'}, + ], + }).then((_user) => { user = _user; api = requester(user); }); @@ -17,7 +24,7 @@ describe('GET /user/tasks/', () => { it('gets all tasks', () => { return api.get(`/user/tasks/`).then((tasks) => { expect(tasks).to.be.an('array'); - expect(tasks.length).to.be.greaterThan(4); + expect(tasks.length).to.be.greaterThan(3); let task = tasks[0]; expect(task.id).to.exist;