Files
habitica/test/helpers/api-unit.helper.js
Matteo Pagliazzi f7be7205e7 Remove localstorage and add notifications (#7588)
* move remaining files frm /common/script/public to website/public

* remove localstorage

* add back noscript template and put all javascript in the footer

* fixes client side tests

* remove double quotes where possible

* simplify jade code and add tests for buildManifest

* loading page with logo and spinner

* better loading screen in landscape mode

* icon on top of text logo

* wip: user.notifications

* notifications: simpler and working code

* finish implementing notifications

* correct loading screen css and re-inline images

* add tests for user notifications

* split User model in multiple files

* remove old comment about missing .catch()

* correctly setup hooks and methods for User model. Cleanup localstorage

* include UserNotificationsService in static page js and split loading-screen css in its own file

* add cron notification and misc fixes

* remove console.log

* fix tests

* fix multiple notifications
2016-06-07 16:14:19 +02:00

105 lines
2.3 KiB
JavaScript

import '../../website/server/libs/api-v3/i18n';
import mongoose from 'mongoose';
import { defaultsDeep as defaults } from 'lodash';
import { model as User } from '../../website/server/models/user';
import { model as Group } from '../../website/server/models/group';
import mongo from './mongo'; // eslint-disable-line
import moment from 'moment';
import i18n from '../../common/script/i18n';
import * as Tasks from '../../website/server/models/task';
afterEach((done) => {
sandbox.restore();
mongoose.connection.db.dropDatabase(done);
});
export { sleep } from './sleep';
export function generateUser (options = {}) {
return new User(options);
}
export function generateGroup (options = {}) {
return new Group(options).toObject();
}
export function generateRes (options = {}) {
let defaultRes = {
render: sandbox.stub(),
send: sandbox.stub(),
status: sandbox.stub().returnsThis(),
sendStatus: sandbox.stub().returnsThis(),
json: sandbox.stub(),
locals: {
user: generateUser(options.localsUser),
group: generateGroup(options.localsGroup),
},
set: sandbox.stub(),
t (string) {
return i18n.t(string);
},
};
return defaults(options, defaultRes);
}
export function generateReq (options = {}) {
let defaultReq = {
body: {},
query: {},
headers: {},
header: sandbox.stub().returns(null),
};
return defaults(options, defaultReq);
}
export function generateNext (func) {
return func || sandbox.stub();
}
export function generateHistory (days) {
let history = [];
let now = Number(moment().toDate());
while (days > 0) {
history.push({
value: days,
date: Number(moment(now).subtract(days, 'days').toDate()),
});
days--;
}
return history;
}
export function generateTodo (user) {
let todo = {
text: 'test todo',
type: 'todo',
value: 0,
completed: false,
};
let task = new Tasks.todo(Tasks.Task.sanitize(todo)); // eslint-disable-line babel/new-cap
task.userId = user._id;
task.save();
return task;
}
export function generateDaily (user) {
let daily = {
text: 'test daily',
type: 'daily',
value: 0,
completed: false,
};
let task = new Tasks.daily(Tasks.Task.sanitize(daily)); // eslint-disable-line babel/new-cap
task.userId = user._id;
task.save();
return task;
}