initial pass at status support

This commit is contained in:
Wyatt Johnson
2017-11-02 17:16:57 -06:00
parent 1f3722edc1
commit 76a255fb7b
49 changed files with 1112 additions and 1598 deletions
@@ -1,27 +1,27 @@
const expect = require('chai').expect;
const Domainlist = require('../../../services/domainlist');
const DomainList = require('../../../services/domain_list');
const SettingsService = require('../../../services/settings');
describe('services.Domainlist', () => {
describe('services.DomainList', () => {
const domainlists = {
const domainLists = {
whitelist: [
'nytimes.com',
'wapo.com'
]
};
let domainlist = new Domainlist();
let domainList = new DomainList();
const settings = {id: '1', moderation: 'PRE', domainlist: {whitelist: ['nytimes.com', 'wapo.com']}};
beforeEach(() => SettingsService.init(settings));
describe('#init', () => {
before(() => domainlist.upsert(domainlists));
before(() => domainList.upsert(domainLists));
it('has entries', () => {
expect(domainlist.lists.whitelist).to.not.be.empty;
expect(domainList.lists.whitelist).to.not.be.empty;
});
});
@@ -92,21 +92,21 @@ describe('services.Domainlist', () => {
['google.Ca:80', 'google.ca'],
['google.Ca:443', 'google.ca'],
].forEach(([domain, hostname]) => {
expect(Domainlist.parseURL(domain), `domain ${domain} should be parsed as ${hostname}`).to.equal(hostname);
expect(DomainList.parseURL(domain), `domain ${domain} should be parsed as ${hostname}`).to.equal(hostname);
});
});
});
describe('#match', () => {
const whiteList = Domainlist.parseList(domainlists['whitelist']);
const whiteList = DomainList.parseList(domainLists['whitelist']);
it('does match on an included domain', () => {
[
'http://wapo.com',
'nytimes.com'
].forEach((domain) => {
expect(domainlist.match(whiteList, domain)).to.be.true;
expect(domainList.match(whiteList, domain)).to.be.true;
});
});
@@ -116,7 +116,7 @@ describe('services.Domainlist', () => {
'www.badsite.com',
'otherexample.com'
].forEach((domain) => {
expect(domainlist.match(whiteList, domain)).to.be.false;
expect(domainList.match(whiteList, domain)).to.be.false;
});
});
});
-22
View File
@@ -1,22 +0,0 @@
describe('services.scraper', () => {
describe('#create', () => {
it('should create a new kue job');
});
describe('#scrape', () => {
it('should scrape complete information');
it('should scrape what it can');
});
describe('#update', () => {
it('should update the database record entries from the meta');
});
describe('#process', () => {
it('should start the processor to scrape assets');
});
describe('#shutdown', () => {
it('should shutdown the job processor');
});
});
+53 -116
View File
@@ -151,21 +151,6 @@ describe('services.UsersService', () => {
});
describe('#setStatus', () => {
it('should set the status to active', () => {
return UsersService
.setStatus(mockUsers[0].id, 'ACTIVE')
.then(() => UsersService.findById(mockUsers[0].id))
.then((user) => {
expect(user).to.have.property('status', 'ACTIVE');
})
.then(() => {
expect(MailerService.sendSimple).to.not.have.been.called;
});
});
});
describe('#ignoreUser', () => {
it('should add user id to ignoredUsers set', async () => {
const user = mockUsers[0];
@@ -194,54 +179,6 @@ describe('services.UsersService', () => {
});
});
describe('#ban', () => {
it('should set the status to banned', () => {
return UsersService
.setStatus(mockUsers[0].id, 'BANNED')
.then(() => UsersService.findById(mockUsers[0].id))
.then((user) => {
expect(user).to.have.property('status', 'BANNED');
})
.then(() => {
expect(MailerService.sendSimple).to.have.been.calledWithMatch({
template: 'banned',
to: mockUsers[0].profiles[0].id
});
});
});
it('should still disable and ban the user if there is no comment', () => {
return UsersService
.setStatus(mockUsers[0].id, 'BANNED')
.then(() => UsersService.findById(mockUsers[0].id))
.then((user) => {
expect(user).to.have.property('status', 'BANNED');
});
});
});
describe('#unban', () => {
it('should set the status to active', () => {
return UsersService
.setStatus(mockUsers[0].id, 'ACTIVE')
.then(() => UsersService.findById(mockUsers[0].id))
.then((user) => {
expect(user).to.have.property('status', 'ACTIVE');
});
});
});
describe('#toggleNameEdit', () => {
it('should toggle the canEditName field', () => {
return UsersService
.toggleNameEdit(mockUsers[0].id, true)
.then(() => UsersService.findById(mockUsers[0].id))
.then((user) => {
expect(user).to.have.property('canEditName', true);
});
});
});
describe('#search', () => {
it('should return all the results without a value', async () => {
expect(await UsersService.search()).to.have.length(3);
@@ -286,63 +223,63 @@ describe('services.UsersService', () => {
});
});
describe('#editName', () => {
it('should let the user edit their username if the proper toggle is set', () => {
return UsersService
.toggleNameEdit(mockUsers[0].id, true)
.then(() => UsersService.editName(mockUsers[0].id, 'Jojo'))
.then(() => UsersService.findById(mockUsers[0].id))
.then((user) => {
expect(user).to.have.property('username', 'Jojo');
expect(user).to.have.property('canEditName', false);
});
});
// describe('#editName', () => {
// it('should let the user edit their username if the proper toggle is set', () => {
// return UsersService
// .toggleNameEdit(mockUsers[0].id, true)
// .then(() => UsersService.editName(mockUsers[0].id, 'Jojo'))
// .then(() => UsersService.findById(mockUsers[0].id))
// .then((user) => {
// expect(user).to.have.property('username', 'Jojo');
// expect(user).to.have.property('canEditName', false);
// });
// });
it('should let the user submit the same username if user is not banned (create username)', () => {
return UsersService
.toggleNameEdit(mockUsers[0].id, true)
.then(() => UsersService.editName(mockUsers[0].id, mockUsers[0].username))
.then(() => UsersService.findById(mockUsers[0].id))
.then((user) => {
expect(user).to.have.property('username', mockUsers[0].username);
expect(user).to.have.property('canEditName', false);
});
});
// it('should let the user submit the same username if user is not banned (create username)', () => {
// return UsersService
// .toggleNameEdit(mockUsers[0].id, true)
// .then(() => UsersService.editName(mockUsers[0].id, mockUsers[0].username))
// .then(() => UsersService.findById(mockUsers[0].id))
// .then((user) => {
// expect(user).to.have.property('username', mockUsers[0].username);
// expect(user).to.have.property('canEditName', false);
// });
// });
it('should return error when a banned user submits the same username (rejected username)', () => {
return UsersService
.toggleNameEdit(mockUsers[0].id, true)
.then(() => UsersService.setStatus(mockUsers[0].id, 'BANNED'))
.then(() => UsersService.editName(mockUsers[0].id, mockUsers[0].username))
.then(() => UsersService.findById(mockUsers[0].id))
.then(() => {
throw new Error('Error expected');
})
.catch((err) => {
expect(err.status).to.equal(400);
expect(err.translation_key).to.equal('SAME_USERNAME_PROVIDED');
});
});
// it('should return error when a banned user submits the same username (rejected username)', () => {
// return UsersService
// .toggleNameEdit(mockUsers[0].id, true)
// .then(() => UsersService.setStatus(mockUsers[0].id, 'BANNED'))
// .then(() => UsersService.editName(mockUsers[0].id, mockUsers[0].username))
// .then(() => UsersService.findById(mockUsers[0].id))
// .then(() => {
// throw new Error('Error expected');
// })
// .catch((err) => {
// expect(err.status).to.equal(400);
// expect(err.translation_key).to.equal('SAME_USERNAME_PROVIDED');
// });
// });
it('should return an error if canEditName is false', async () => {
return expect(UsersService.editName(mockUsers[0].id, 'Jojo')).to.eventually.be.rejected;
});
// it('should return an error if canEditName is false', async () => {
// return expect(UsersService.editName(mockUsers[0].id, 'Jojo')).to.eventually.be.rejected;
// });
it('should return an error if the username is already taken', async () => {
await UsersService.toggleNameEdit(mockUsers[0].id, true);
return expect(UsersService.editName(mockUsers[0].id, 'Marvel')).to.eventually.be.rejected;
});
// it('should return an error if the username is already taken', async () => {
// await UsersService.toggleNameEdit(mockUsers[0].id, true);
// return expect(UsersService.editName(mockUsers[0].id, 'Marvel')).to.eventually.be.rejected;
// });
it('should not allow non-alphanumeric characters in usernames', () => {
return UsersService
.isValidUsername('hi🖕')
.then(() => {
expect(false).to.be.true;
})
.catch((err) => {
expect(err).to.be.ok;
});
});
});
// it('should not allow non-alphanumeric characters in usernames', () => {
// return UsersService
// .isValidUsername('hi🖕')
// .then(() => {
// expect(false).to.be.true;
// })
// .catch((err) => {
// expect(err).to.be.ok;
// });
// });
// });
});