Skip to content

Commit 9de14af

Browse files
committed
feat(unit-tests): add tests for SubmitValidator
1 parent 39af3ef commit 9de14af

File tree

3 files changed

+396
-22
lines changed

3 files changed

+396
-22
lines changed

test/e2e/SubmitScenario.spec.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ const source = `
2424
const testcases = [
2525
{
2626
id: 1,
27-
stdin: 'https://minio.cb.lk/public/input',
28-
stdout: 'https://minio.cb.lk/public/input'
27+
input: 'https://minio.cb.lk/public/input',
28+
output: 'https://minio.cb.lk/public/input'
2929
},
3030
{
3131
id: 2,
32-
stdin: 'https://minio.cb.lk/public/input',
33-
stdout: 'https://minio.cb.lk/public/input'
32+
input: 'https://minio.cb.lk/public/input',
33+
output: 'https://minio.cb.lk/public/input'
3434
}
3535
];
3636
const expectedResult = 'Success';
@@ -215,4 +215,22 @@ describe('POST api/submissions', () => {
215215
expect(res.status).to.equal(200);
216216
expect(resultFromCallBack.result).to.equal(expectedResult);
217217
});
218+
219+
it('should throw 400 error for incorrect testcases ', async () => {
220+
const params = {
221+
source: (new Buffer(source).toString('base64')),
222+
lang: 'cpp',
223+
mode: 'poll',
224+
timelimit: 1,
225+
testcases: []
226+
};
227+
228+
const res = await chai.request(app).post(`/api/submissions`).set({
229+
Authorization: 'Bearer 7718330d2794406c980bdbded6c9dc1d',
230+
Accept: 'application/json'
231+
}).send(params);
232+
233+
expect(res.status).to.equal(400);
234+
expect(res.body.err.message).to.equal('"testcases" must contain at least 1 items');
235+
});
218236
});

test/unit/validators/RunValidator.spec.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,23 @@ describe('RunValidator', async () => {
137137
expect(sentData.err.message).to.equal('"mode" must be one of [sync, callback, poll]');
138138
});
139139

140+
it('should throw error if mode is callback and callback is missing', async () => {
141+
const req = {
142+
body: {
143+
source: 'LKJSDFKLMC414CcnBcba12',
144+
lang: 'cpp',
145+
mode: 'callback',
146+
stdin: ''
147+
}
148+
};
149+
150+
await runValidator.POST(req, res, nextSpy);
151+
152+
expect(sentStatus).to.be.equal(400);
153+
expect(sentData.err.message).to.equal('"callback" is required');
154+
expect(nextSpy.calledOnce).to.be.false;
155+
});
156+
140157
it('should not throw an error with STDIN missing', async () => {
141158
const req = {
142159
body: {
@@ -200,24 +217,7 @@ describe('RunValidator', async () => {
200217
expect(nextSpy.calledOnce).to.be.false;
201218
});
202219

203-
it('should throw error if mode is callback and callback is missing', async () => {
204-
const req = {
205-
body: {
206-
source: 'LKJSDFKLMC414CcnBcba12',
207-
lang: 'cpp',
208-
mode: 'callback',
209-
stdin: ''
210-
}
211-
};
212-
213-
await runValidator.POST(req, res, nextSpy);
214-
215-
expect(sentStatus).to.be.equal(400);
216-
expect(sentData.err.message).to.equal('"callback" is required');
217-
expect(nextSpy.calledOnce).to.be.false;
218-
});
219-
220-
it('shoud NOT throw error for correct values', async () => {
220+
it('should NOT throw error for correct values', async () => {
221221
const req = {
222222
body: {
223223
source: 'LKJSDFKLMC414CcnBcba12',

0 commit comments

Comments
 (0)