replaced eslint:recommended with prettier

This commit is contained in:
Wyatt Johnson
2018-01-11 20:00:34 -07:00
parent d56c19016a
commit 0abc2ca243
649 changed files with 16235 additions and 13008 deletions
+38 -27
View File
@@ -12,9 +12,12 @@ const AssetsService = require('../../../../../services/assets');
const SettingsService = require('../../../../../services/settings');
describe('/api/v1/assets', () => {
beforeEach(async () => {
const settings = {id: '1', moderation: 'PRE', domains: {whitelist: ['test.com']}};
const settings = {
id: '1',
moderation: 'PRE',
domains: { whitelist: ['test.com'] },
};
await SettingsService.init(settings);
@@ -23,24 +26,24 @@ describe('/api/v1/assets', () => {
url: 'https://coralproject.net/news/asset1',
title: 'Asset 1',
description: 'term1',
closedAt: Date.now()
closedAt: Date.now(),
},
{
url: 'https://coralproject.net/news/asset2',
title: 'Asset 2',
description: 'term2',
closedAt: null
}
closedAt: null,
},
]);
});
describe('#get', () => {
it('should return all assets without a search query', async () => {
for (const role of ['ADMIN', 'MODERATOR']) {
const res = await chai.request(app)
const res = await chai
.request(app)
.get('/api/v1/assets')
.set(passport.inject({role}));
.set(passport.inject({ role }));
const body = res.body;
@@ -55,9 +58,10 @@ describe('/api/v1/assets', () => {
it('should return assets that we search for', async () => {
for (const role of ['ADMIN', 'MODERATOR']) {
const res = await chai.request(app)
const res = await chai
.request(app)
.get('/api/v1/assets?value=term2')
.set(passport.inject({role}));
.set(passport.inject({ role }));
const body = res.body;
@@ -70,16 +74,20 @@ describe('/api/v1/assets', () => {
const asset = assets[0];
expect(asset).to.have.property('url', 'https://coralproject.net/news/asset2');
expect(asset).to.have.property(
'url',
'https://coralproject.net/news/asset2'
);
expect(asset).to.have.property('title', 'Asset 2');
}
});
it('should not return assets that we do not search for', async () => {
for (const role of ['ADMIN', 'MODERATOR']) {
const res = await chai.request(app)
const res = await chai
.request(app)
.get('/api/v1/assets?value=term3')
.set(passport.inject({role}));
.set(passport.inject({ role }));
const body = res.body;
expect(body).to.have.property('count', 0);
@@ -91,9 +99,10 @@ describe('/api/v1/assets', () => {
it('should return only closed assets', async () => {
for (const role of ['ADMIN', 'MODERATOR']) {
const res = await chai.request(app)
const res = await chai
.request(app)
.get('/api/v1/assets?filter=closed')
.set(passport.inject({role}));
.set(passport.inject({ role }));
const body = res.body;
expect(body).to.have.property('count', 1);
@@ -107,9 +116,10 @@ describe('/api/v1/assets', () => {
it('should return only opened assets', async () => {
for (const role of ['ADMIN', 'MODERATOR']) {
const res = await chai.request(app)
const res = await chai
.request(app)
.get('/api/v1/assets?filter=open')
.set(passport.inject({role}));
.set(passport.inject({ role }));
const body = res.body;
expect(body).to.have.property('count', 1);
@@ -120,28 +130,29 @@ describe('/api/v1/assets', () => {
expect(assets[0]).to.have.property('title', 'Asset 2');
}
});
});
describe('#put', () => {
it('should close the asset', async () => {
const today = Date.now();
const asset = await AssetsService.findOrCreateByUrl('http://test.com');
expect(asset).to.have.property('isClosed', false);
expect(asset).to.have.property('closedAt', null);
const res = await chai.request(app)
const res = await chai
.request(app)
.put(`/api/v1/assets/${asset.id}/status`)
.set(passport.inject({role: 'ADMIN'}))
.send({closedAt: today});
.set(passport.inject({ role: 'ADMIN' }))
.send({ closedAt: today });
expect(res).to.have.status(204);
const closedAsset = await AssetsService.findByUrl('http://test.com');
expect(closedAsset).to.have.property('isClosed', true);
expect(closedAsset).to.have.property('closedAt').and.to.not.equal(null);
expect(closedAsset)
.to.have.property('closedAt')
.and.to.not.equal(null);
});
it('should require ADMIN role', async () => {
@@ -151,12 +162,12 @@ describe('/api/v1/assets', () => {
expect(asset).to.have.property('isClosed', false);
expect(asset).to.have.property('closedAt', null);
const promise = chai.request(app)
const promise = chai
.request(app)
.put(`/api/v1/assets/${asset.id}/status`)
.set(passport.inject({role: 'MODERATOR'}))
.send({closedAt: today});
.set(passport.inject({ role: 'MODERATOR' }))
.send({ closedAt: today });
await expect(promise).to.eventually.be.rejected;
});
});
});
+39 -24
View File
@@ -10,9 +10,10 @@ const UsersService = require('../../../../../services/users');
describe('/api/v1/auth', () => {
describe('#get', () => {
it('should return nothing when no user is logged in', () => {
return chai.request(app)
return chai
.request(app)
.get('/api/v1/auth')
.then((res) => {
.then(res => {
expect(res.status).to.be.equal(204);
expect(res).to.not.have.a.body;
});
@@ -23,23 +24,29 @@ describe('/api/v1/auth', () => {
const SettingsService = require('../../../../../services/settings');
describe('/api/v1/auth/local', () => {
let mockUser;
beforeEach(async () => {
const settings = {requireEmailConfirmation: false, wordlist: {banned: ['bad'], suspect: ['naughty']}};
const settings = {
requireEmailConfirmation: false,
wordlist: { banned: ['bad'], suspect: ['naughty'] },
};
await SettingsService.init(settings);
mockUser = await UsersService.createLocalUser('maria@gmail.com', 'password!', 'Maria');
mockUser = await UsersService.createLocalUser(
'maria@gmail.com',
'password!',
'Maria'
);
});
describe('email confirmation disabled', () => {
describe('#post', () => {
it('should send back the user on a successful login', () => {
return chai.request(app)
return chai
.request(app)
.post('/api/v1/auth/local')
.send({email: 'maria@gmail.com', password: 'password!'})
.then((res2) => {
.send({ email: 'maria@gmail.com', password: 'password!' })
.then(res2 => {
expect(res2).to.have.status(200);
expect(res2).to.be.json;
expect(res2.body).to.have.property('user');
@@ -48,42 +55,50 @@ describe('/api/v1/auth/local', () => {
});
it('should not send back the user on a unsuccessful login', () => {
return chai.request(app)
return chai
.request(app)
.post('/api/v1/auth/local')
.send({email: 'maria@gmail.com', password: 'password!3'})
.catch((err) => {
.send({ email: 'maria@gmail.com', password: 'password!3' })
.catch(err => {
expect(err).to.not.be.null;
expect(err.response).to.have.status(401);
expect(err.response.body).to.have.property('message', 'You are not authorized to perform this action.');
expect(err.response.body).to.have.property(
'message',
'You are not authorized to perform this action.'
);
});
});
});
});
describe('email confirmation enabled', () => {
beforeEach(() => SettingsService.update({requireEmailConfirmation: true}));
beforeEach(() =>
SettingsService.update({ requireEmailConfirmation: true })
);
describe('#post', () => {
it('should not allow a login from a user that is not confirmed', () => {
return chai.request(app)
return chai
.request(app)
.post('/api/v1/auth/local')
.send({email: 'maria@gmail.com', password: 'password!'})
.catch((err) => {
.send({ email: 'maria@gmail.com', password: 'password!' })
.catch(err => {
expect(err).to.have.status(401);
err.response.body.should.have.property('error');
return UsersService.createEmailConfirmToken(mockUser, mockUser.profiles[0].id);
return UsersService.createEmailConfirmToken(
mockUser,
mockUser.profiles[0].id
);
})
.then(UsersService.verifyEmailConfirmation)
.then(() => {
return chai.request(app)
return chai
.request(app)
.post('/api/v1/auth/local')
.send({email: 'maria@gmail.com', password: 'password!'});
.send({ email: 'maria@gmail.com', password: 'password!' });
})
.then((res) => {
.then(res => {
expect(res).to.have.status(200);
expect(res).to.be.json;
expect(res.body).to.have.property('user');
+14 -15
View File
@@ -8,19 +8,18 @@ chai.use(require('chai-http'));
const expect = chai.expect;
const SettingsService = require('../../../../../services/settings');
const defaults = {id: '1', moderation: 'PRE'};
const defaults = { id: '1', moderation: 'PRE' };
describe('/api/v1/settings', () => {
beforeEach(() => SettingsService.init(defaults));
describe('#get', () => {
it('should return a settings object', async () => {
for (let role of ['ADMIN', 'MODERATOR']) {
const res = await chai.request(app)
const res = await chai
.request(app)
.get('/api/v1/settings')
.set(passport.inject({role}));
.set(passport.inject({ role }));
expect(res).to.have.status(200);
expect(res).to.be.json;
expect(res.body).to.have.property('moderation', 'PRE');
@@ -29,29 +28,29 @@ describe('/api/v1/settings', () => {
});
describe('#put', () => {
it('should update the settings', () => {
return chai.request(app)
return chai
.request(app)
.put('/api/v1/settings')
.set(passport.inject({role: 'ADMIN'}))
.send({moderation: 'POST'})
.then((res) => {
.set(passport.inject({ role: 'ADMIN' }))
.send({ moderation: 'POST' })
.then(res => {
expect(res).to.have.status(204);
return SettingsService.retrieve();
})
.then((settings) => {
.then(settings => {
expect(settings).to.have.property('moderation', 'POST');
});
});
it('should require ADMIN role', () => {
const promise = chai.request(app)
const promise = chai
.request(app)
.put('/api/v1/settings')
.set(passport.inject({role: 'MODERATOR'}))
.send({moderation: 'POST'});
.set(passport.inject({ role: 'MODERATOR' }))
.send({ moderation: 'POST' });
return expect(promise).to.eventually.be.rejected;
});
});
});
+26 -14
View File
@@ -4,7 +4,11 @@ const app = require('../../../../../app');
const mailer = require('../../../../../services/mailer');
const SettingsService = require('../../../../../services/settings');
const settings = {id: '1', moderation: 'PRE', wordlist: {banned: ['bad words'], suspect: ['suspect words']}};
const settings = {
id: '1',
moderation: 'PRE',
wordlist: { banned: ['bad words'], suspect: ['suspect words'] },
};
const chai = require('chai');
chai.should();
@@ -14,34 +18,42 @@ const expect = chai.expect;
const UsersService = require('../../../../../services/users');
describe('/api/v1/users/:user_id/email/confirm', () => {
let mockUser;
beforeEach(() => SettingsService.init(settings).then(() => {
return UsersService.createLocalUser('ana@gmail.com', '123321123', 'Ana');
})
.then((user) => {
mockUser = user;
}));
beforeEach(() =>
SettingsService.init(settings)
.then(() => {
return UsersService.createLocalUser(
'ana@gmail.com',
'123321123',
'Ana'
);
})
.then(user => {
mockUser = user;
})
);
describe('#post', () => {
it('should send an email when we hit the endpoint', () => {
expect(mailer.task.tasks).to.have.length(0);
return chai.request(app)
return chai
.request(app)
.post(`/api/v1/users/${mockUser.id}/email/confirm`)
.set(passport.inject({role: 'ADMIN'}))
.then((res) => {
.set(passport.inject({ role: 'ADMIN' }))
.then(res => {
expect(res).to.have.status(204);
expect(mailer.task.tasks).to.have.length(1);
});
});
it('should send a 404 on not matching a user', () => {
return chai.request(app)
return chai
.request(app)
.post(`/api/v1/users/${mockUser.id}/email/confirm`)
.set(passport.inject({role: 'ADMIN'}))
.then((res) => {
.set(passport.inject({ role: 'ADMIN' }))
.then(res => {
expect(res).to.have.status(204);
expect(mailer.task.tasks).to.have.length(1);
});