mirror of
https://github.com/wassname/talk.git
synced 2026-07-26 13:37:38 +08:00
Merge branch 'master' into story/150636425
This commit is contained in:
@@ -37,78 +37,88 @@ describe('/api/v1/assets', () => {
|
||||
describe('#get', () => {
|
||||
|
||||
it('should return all assets without a search query', async () => {
|
||||
const res = await chai.request(app)
|
||||
.get('/api/v1/assets')
|
||||
.set(passport.inject({roles: ['ADMIN']}));
|
||||
for (const role of ['ADMIN', 'MODERATOR']) {
|
||||
const res = await chai.request(app)
|
||||
.get('/api/v1/assets')
|
||||
.set(passport.inject({roles: [role]}));
|
||||
|
||||
const body = res.body;
|
||||
const body = res.body;
|
||||
|
||||
expect(body).to.have.property('count', 2);
|
||||
expect(body).to.have.property('result');
|
||||
expect(body).to.have.property('count', 2);
|
||||
expect(body).to.have.property('result');
|
||||
|
||||
const assets = body.result;
|
||||
const assets = body.result;
|
||||
|
||||
expect(assets).to.have.length(2);
|
||||
expect(assets).to.have.length(2);
|
||||
}
|
||||
});
|
||||
|
||||
it('should return assets that we search for', async () => {
|
||||
const res = await chai.request(app)
|
||||
.get('/api/v1/assets?search=term2')
|
||||
.set(passport.inject({roles: ['ADMIN']}));
|
||||
for (const role of ['ADMIN', 'MODERATOR']) {
|
||||
const res = await chai.request(app)
|
||||
.get('/api/v1/assets?search=term2')
|
||||
.set(passport.inject({roles: [role]}));
|
||||
|
||||
const body = res.body;
|
||||
const body = res.body;
|
||||
|
||||
expect(body).to.have.property('count', 1);
|
||||
expect(body).to.have.property('result');
|
||||
expect(body).to.have.property('count', 1);
|
||||
expect(body).to.have.property('result');
|
||||
|
||||
const assets = body.result;
|
||||
const assets = body.result;
|
||||
|
||||
expect(assets).to.have.length(1);
|
||||
expect(assets).to.have.length(1);
|
||||
|
||||
const asset = assets[0];
|
||||
const asset = assets[0];
|
||||
|
||||
expect(asset).to.have.property('url', 'https://coralproject.net/news/asset2');
|
||||
expect(asset).to.have.property('title', 'Asset 2');
|
||||
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 () => {
|
||||
const res = await chai.request(app)
|
||||
.get('/api/v1/assets?search=term3')
|
||||
.set(passport.inject({roles: ['ADMIN']}));
|
||||
const body = res.body;
|
||||
for (const role of ['ADMIN', 'MODERATOR']) {
|
||||
const res = await chai.request(app)
|
||||
.get('/api/v1/assets?search=term3')
|
||||
.set(passport.inject({roles: [role]}));
|
||||
const body = res.body;
|
||||
|
||||
expect(body).to.have.property('count', 0);
|
||||
expect(body).to.have.property('result');
|
||||
expect(body).to.have.property('count', 0);
|
||||
expect(body).to.have.property('result');
|
||||
|
||||
expect(body.result).to.be.empty;
|
||||
expect(body.result).to.be.empty;
|
||||
}
|
||||
});
|
||||
|
||||
it('should return only closed assets', async () => {
|
||||
const res = await chai.request(app)
|
||||
.get('/api/v1/assets?filter=closed')
|
||||
.set(passport.inject({roles: ['ADMIN']}));
|
||||
const body = res.body;
|
||||
for (const role of ['ADMIN', 'MODERATOR']) {
|
||||
const res = await chai.request(app)
|
||||
.get('/api/v1/assets?filter=closed')
|
||||
.set(passport.inject({roles: [role]}));
|
||||
const body = res.body;
|
||||
|
||||
expect(body).to.have.property('count', 1);
|
||||
expect(body).to.have.property('result');
|
||||
expect(body).to.have.property('count', 1);
|
||||
expect(body).to.have.property('result');
|
||||
|
||||
const assets = body.result;
|
||||
const assets = body.result;
|
||||
|
||||
expect(assets[0]).to.have.property('title', 'Asset 1');
|
||||
expect(assets[0]).to.have.property('title', 'Asset 1');
|
||||
}
|
||||
});
|
||||
|
||||
it('should return only opened assets', async () => {
|
||||
const res = await chai.request(app)
|
||||
.get('/api/v1/assets?filter=open')
|
||||
.set(passport.inject({roles: ['ADMIN']}));
|
||||
const body = res.body;
|
||||
for (const role of ['ADMIN', 'MODERATOR']) {
|
||||
const res = await chai.request(app)
|
||||
.get('/api/v1/assets?filter=open')
|
||||
.set(passport.inject({roles: [role]}));
|
||||
const body = res.body;
|
||||
|
||||
expect(body).to.have.property('count', 1);
|
||||
expect(body).to.have.property('result');
|
||||
expect(body).to.have.property('count', 1);
|
||||
expect(body).to.have.property('result');
|
||||
|
||||
const assets = body.result;
|
||||
const assets = body.result;
|
||||
|
||||
expect(assets[0]).to.have.property('title', 'Asset 2');
|
||||
expect(assets[0]).to.have.property('title', 'Asset 2');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
@@ -133,6 +143,20 @@ describe('/api/v1/assets', () => {
|
||||
expect(closedAsset).to.have.property('isClosed', true);
|
||||
expect(closedAsset).to.have.property('closedAt').and.to.not.equal(null);
|
||||
});
|
||||
|
||||
it('should require ADMIN role', 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 promise = chai.request(app)
|
||||
.put(`/api/v1/assets/${asset.id}/status`)
|
||||
.set(passport.inject({roles: ['MODERATOR']}))
|
||||
.send({closedAt: today});
|
||||
await expect(promise).to.eventually.be.rejected;
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -16,17 +16,17 @@ describe('/api/v1/settings', () => {
|
||||
|
||||
describe('#get', () => {
|
||||
|
||||
it('should return a settings object', () => {
|
||||
return chai.request(app)
|
||||
.get('/api/v1/settings')
|
||||
.set(passport.inject({
|
||||
roles: ['ADMIN']
|
||||
}))
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200);
|
||||
expect(res).to.be.json;
|
||||
expect(res.body).to.have.property('moderation', 'PRE');
|
||||
});
|
||||
it('should return a settings object', async () => {
|
||||
for (let role of ['ADMIN', 'MODERATOR']) {
|
||||
const res = await chai.request(app)
|
||||
.get('/api/v1/settings')
|
||||
.set(passport.inject({
|
||||
roles: [role]
|
||||
}));
|
||||
expect(res).to.have.status(200);
|
||||
expect(res).to.be.json;
|
||||
expect(res.body).to.have.property('moderation', 'PRE');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -46,6 +46,14 @@ describe('/api/v1/settings', () => {
|
||||
expect(settings).to.have.property('moderation', 'POST');
|
||||
});
|
||||
});
|
||||
|
||||
it('should require ADMIN role', () => {
|
||||
const promise = chai.request(app)
|
||||
.put('/api/v1/settings')
|
||||
.set(passport.inject({roles: ['MODERATOR']}))
|
||||
.send({moderation: 'POST'});
|
||||
return expect(promise).to.eventually.be.rejected;
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -27,44 +27,10 @@ describe('services.Wordlist', () => {
|
||||
|
||||
beforeEach(() => SettingsService.init(settings));
|
||||
|
||||
describe('#init', () => {
|
||||
describe('#regexp', () => {
|
||||
|
||||
before(() => wordlist.upsert(wordlists));
|
||||
|
||||
it('parses the wordlists correctly', () => {
|
||||
expect(wordlist.lists.banned).to.deep.equal([
|
||||
[ 'cookies' ],
|
||||
[ 'how', 'to', 'do', 'bad', 'things' ],
|
||||
[ 'how', 'to', 'do', 'really', 'bad', 'things' ],
|
||||
[ 's', 'h', 'i', 't' ],
|
||||
[ '$hit' ],
|
||||
[ 'p**ch' ],
|
||||
[ 'p*ch' ],
|
||||
]);
|
||||
expect(wordlist.lists.suspect).to.deep.equal([
|
||||
[ 'do', 'bad', 'things' ],
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#parseList', () => {
|
||||
it('does not include emojis in the wordlist', () => {
|
||||
let list = Wordlist.parseList([
|
||||
'🖕',
|
||||
'🖕 asdf',
|
||||
'asd🖕asdf',
|
||||
'asd🖕',
|
||||
]);
|
||||
|
||||
expect(list).to.have.length(0);
|
||||
});
|
||||
});
|
||||
|
||||
const bannedList = Wordlist.parseList(wordlists.banned);
|
||||
|
||||
describe('#match', () => {
|
||||
|
||||
it('does match on a bad word', () => {
|
||||
[
|
||||
'how to do really bad things',
|
||||
@@ -76,7 +42,7 @@ describe('services.Wordlist', () => {
|
||||
'This stuff is $hit!',
|
||||
'That\'s a p**ch!',
|
||||
].forEach((word) => {
|
||||
expect(wordlist.match(bannedList, word)).to.be.true;
|
||||
expect(wordlist.regexp.banned.test(word)).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -90,7 +56,7 @@ describe('services.Wordlist', () => {
|
||||
'I have bad $ hit lling',
|
||||
'That\'s a p***ch!',
|
||||
].forEach((word) => {
|
||||
expect(wordlist.match(bannedList, word)).to.be.false;
|
||||
expect(wordlist.regexp.banned.test(word)).to.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -129,26 +95,6 @@ describe('services.Wordlist', () => {
|
||||
|
||||
});
|
||||
|
||||
describe('#checkName', () => {
|
||||
[
|
||||
'flowers',
|
||||
'joy',
|
||||
'lots_of_candy'
|
||||
].forEach((username) => {
|
||||
it(`does not match on list=banned name=${username}`, () => {
|
||||
expect(wordlist.checkName(bannedList, username)).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
[
|
||||
'cookies'
|
||||
].forEach((username) => {
|
||||
it(`does match on list=banned name=${username}`, () => {
|
||||
expect(wordlist.checkName(bannedList, username)).to.be.false;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#filter', () => {
|
||||
|
||||
before(() => wordlist.upsert(wordlists));
|
||||
|
||||
Reference in New Issue
Block a user