Skip to content

Commit 89beef0

Browse files
committed
feat(e2e-tests): add test/utils (helper functions)
1 parent 9d3ede8 commit 89beef0

File tree

3 files changed

+52
-68
lines changed

3 files changed

+52
-68
lines changed

test/utils/setup-db-server.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

test/utils/setup-mock-queue.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

test/utils/utils.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import * as amqp from 'amqplib/callback_api';
2+
import config = require('../../config');
3+
import DB from "../../src/models";
4+
5+
6+
const jobQ = 'job_queue'
7+
const successQ = 'success_queue'
8+
9+
export async function setupMockQueue(){
10+
amqp.connect(`amqp://${config.AMQP.USER}:${config.AMQP.PASS}@${config.AMQP.HOST}:${config.AMQP.PORT}`,
11+
(err, connection) => {
12+
if (err) throw err
13+
14+
connection.createChannel((err2, channel) => {
15+
16+
channel.assertQueue(successQ)
17+
channel.assertQueue(jobQ)
18+
channel.consume(jobQ, (msg) => {
19+
const job = JSON.parse(msg.content.toString())
20+
let payload;
21+
if (job.testcases ) {
22+
// submit_result
23+
payload = {
24+
id: job.id,
25+
time: 1,
26+
result: 'Success',
27+
score: 100,
28+
testcases: []
29+
}
30+
}
31+
else {
32+
// run_result
33+
payload = {
34+
id: job.id,
35+
stderr: 'Success',
36+
stdout: 'Success'
37+
}
38+
}
39+
setTimeout(() => {
40+
channel.sendToQueue(successQ, (new Buffer(JSON.stringify(payload))))
41+
channel.ack(msg)
42+
}, 1000)
43+
})
44+
})
45+
})
46+
}
47+
48+
export async function truncateTables() {
49+
await DB.apikeys.destroy({truncate: true});
50+
await DB.langs.destroy({truncate: true});
51+
await DB.submissions.destroy({truncate: true});
52+
}

0 commit comments

Comments
 (0)