Skip to content

Commit

Permalink
test: add db cleanup before rerun (#4750)
Browse files Browse the repository at this point in the history
* test: add db cleanup before rerun

* update

* cleanup by 1=1
  • Loading branch information
sogehige committed Jul 28, 2021
1 parent 7831b6d commit 2137da9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Expand Up @@ -3,7 +3,7 @@
const assert = require('assert');

require('../../general.js');
const { getRepository } = require('typeorm');
const { getRepository, getConnection } = require('typeorm');

const { Permissions } = require('../../../dest/database/entity/permissions');
const { defaultPermissions } = require('../../../dest/helpers/permissions/defaultPermissions');
Expand All @@ -15,7 +15,12 @@ const user = require('../../general.js').user;

describe('discord#868236481406324747 - Manually included users with link disabled should not be purged', () => {
after(async () => {
await getRepository(Permissions).clear();
await getConnection()
.createQueryBuilder()
.delete()
.from(Permissions)
.where('1 = 1')
.execute();
await getRepository(Permissions).insert({
id: defaultPermissions.CASTERS,
name: 'Casters',
Expand Down Expand Up @@ -89,7 +94,12 @@ describe('discord#868236481406324747 - Manually included users with link disable
await message.prepare();
await user.prepare();

await getRepository(Permissions).clear();
await getConnection()
.createQueryBuilder()
.delete()
.from(Permissions)
.where('1 = 1')
.execute();
await getRepository(Permissions).insert({
id: defaultPermissions.CASTERS,
name: 'Casters',
Expand Down Expand Up @@ -179,6 +189,10 @@ describe('discord#868236481406324747 - Manually included users with link disable
moderation.__permission_based__cLinksEnabled[defaultPermissions.VIEWERS] = true;
});

it (`Enable link moderation for Test group`, () => {
moderation.__permission_based__cLinksEnabled['162e0172-bf00-41d7-b363-346bea52838b'] = true;
});

it(`Link 'http://www.foobarpage.com' should timeout`, async () => {
assert(!(await moderation.containsLink({ sender: user.viewer, message: 'http://www.foobarpage.com' })));
});
Expand Down
7 changes: 7 additions & 0 deletions tools/runTests.js
Expand Up @@ -12,6 +12,13 @@ async function retest() {
return o.trim().split(/\d\) /)[1];
}))) {
await new Promise((resolve) => {
console.log('------------------------------------------------------------------------------');
console.log('\tRemoving sogebot.db file');
console.log('------------------------------------------------------------------------------');
if (fs.existsSync('./sogebot.db')) {
fs.unlinkSync('./sogebot.db');
}

console.log('------------------------------------------------------------------------------');
console.log('\t=> Re-Running ' + suite + ' tests');
console.log('------------------------------------------------------------------------------');
Expand Down

0 comments on commit 2137da9

Please sign in to comment.