Skip to content

Commit e418264

Browse files
Merge pull request #60 from prabalsingh24/chai-tests
Chai Mocha tests
2 parents f077ff9 + 5c65914 commit e418264

22 files changed

+1423
-193
lines changed

config.js

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

config/development.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
exports = module.exports = {
2+
RUN: {
3+
TIMEOUT: process.env.RUN_TIMEOUT || 10000,
4+
},
5+
6+
// Domain/Host on which judge-api is hosted
7+
HOST: process.env.JUDGEAPI_HOST || 'localhost',
8+
// Port on which this app will run
9+
PORT: process.env.JUDGEAPI_PORT || 3737,
10+
11+
// Database config for a postgresql db (docker based or native)
12+
DB: {
13+
DATABASE: process.env.DB_NAME || 'judgeapi-dev',
14+
USERNAME: process.env.DB_USER || 'judgeapi',
15+
PASSWORD: process.env.DB_PASS || 'judgeapi',
16+
HOST: process.env.DB_HOST || 'localhost'
17+
},
18+
19+
// Rabbit MQ queue - the other end of which is attached
20+
// to judge-taskmaster
21+
AMQP: {
22+
USER: process.env.AMQP_USER || 'codingblocks',
23+
PASS: process.env.AMQP_PASS || 'codingblocks',
24+
HOST: process.env.AMQP_HOST || 'localhost',
25+
PORT: process.env.AMQP_PORT || 5672
26+
},
27+
28+
S3: {
29+
endpoint: process.env.S3_ENDPOINT || 'localhost',
30+
port: process.env.S3_PORT || 9000,
31+
ssl: process.env.S3_SSL || false,
32+
accessKey: process.env.S3_ACCESS_KEY || '',
33+
secretKey: process.env.S3_SECRET_KEY || '',
34+
bucket: process.env.S3_BUCKET || 'judge-submissions',
35+
region: process.env.S3_REGION || 'us-east-1'
36+
}
37+
}

config/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const developmentConfig = require('./development');
2+
const testConfig = require('./test');
3+
const productionConfig = require('./production');
4+
5+
const env = process.env.NODE_ENV || 'development';
6+
7+
if (env === 'test') {
8+
module.exports = testConfig;
9+
}
10+
else if(env === 'production') {
11+
module.exports = productionConfig;
12+
}
13+
else {
14+
module.exports = developmentConfig;
15+
}

config/production.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
exports = module.exports = {
2+
RUN: {
3+
TIMEOUT: process.env.RUN_TIMEOUT || 10000,
4+
},
5+
6+
// Domain/Host on which judge-api is hosted
7+
HOST: process.env.JUDGEAPI_HOST || 'localhost',
8+
// Port on which this app will run
9+
PORT: process.env.JUDGEAPI_PORT || 3737,
10+
11+
// Database config for a postgresql db (docker based or native)
12+
DB: {
13+
DATABASE: process.env.DB_NAME || 'judgeapi-dev',
14+
USERNAME: process.env.DB_USER || 'judgeapi',
15+
PASSWORD: process.env.DB_PASS || 'judgeapi',
16+
HOST: process.env.DB_HOST || 'localhost'
17+
},
18+
19+
// Rabbit MQ queue - the other end of which is attached
20+
// to judge-taskmaster
21+
AMQP: {
22+
USER: process.env.AMQP_USER || 'codingblocks',
23+
PASS: process.env.AMQP_PASS || 'codingblocks',
24+
HOST: process.env.AMQP_HOST || 'localhost',
25+
PORT: process.env.AMQP_PORT || 5672
26+
},
27+
28+
S3: {
29+
endpoint: process.env.S3_ENDPOINT || 'localhost',
30+
port: process.env.S3_PORT || 9000,
31+
ssl: process.env.S3_SSL || false,
32+
accessKey: process.env.S3_ACCESS_KEY || '',
33+
secretKey: process.env.S3_SECRET_KEY || '',
34+
bucket: process.env.S3_BUCKET || 'judge-submissions',
35+
region: process.env.S3_REGION || 'us-east-1'
36+
}
37+
}

config/test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
exports = module.exports = {
2+
RUN: {
3+
TIMEOUT: process.env.RUN_TIMEOUT || 10000,
4+
},
5+
6+
// Domain/Host on which judge-api is hosted
7+
HOST: process.env.JUDGEAPI_HOST || 'localhost',
8+
// Port on which this app will run
9+
PORT: process.env.JUDGEAPI_PORT || 3737,
10+
11+
// Database config for a postgresql db (docker based or native)
12+
DB: {
13+
DATABASE: process.env.DB_NAME || 'judgeapi-test',
14+
USERNAME: process.env.DB_USER || 'judgeapi',
15+
PASSWORD: process.env.DB_PASS || 'judgeapi',
16+
HOST: process.env.DB_HOST || 'localhost'
17+
},
18+
19+
// Rabbit MQ queue - the other end of which is attached
20+
// to judge-taskmaster
21+
AMQP: {
22+
USER: process.env.AMQP_USER || 'codingblocks',
23+
PASS: process.env.AMQP_PASS || 'codingblocks',
24+
HOST: process.env.AMQP_HOST || 'localhost',
25+
PORT: process.env.AMQP_PORT || 5672
26+
},
27+
28+
S3: {
29+
endpoint: process.env.S3_ENDPOINT || 'localhost',
30+
port: process.env.S3_PORT || 9000,
31+
ssl: process.env.S3_SSL || false,
32+
accessKey: process.env.S3_ACCESS_KEY || '',
33+
secretKey: process.env.S3_SECRET_KEY || '',
34+
bucket: process.env.S3_BUCKET || 'judge-submissions',
35+
region: process.env.S3_REGION || 'us-east-1'
36+
}
37+
}

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414
"apidoc": "^0.17.6",
1515
"base-64": "^0.1.0",
1616
"cross-env": "^7.0.2",
17+
"chai-as-promised": "^7.1.1",
18+
"chai-http": "^4.3.0",
1719
"debug": "^4.0.0",
1820
"express": "^4.16.2",
1921
"minio": "^7.0.3",
2022
"pg": "^7.4.3",
2123
"pg-hstore": "^2.3.2",
2224
"sequelize": "^4.22.6",
25+
"sinon": "^9.0.2",
2326
"uuid": "^7.0.1"
2427
},
2528
"devDependencies": {
@@ -31,7 +34,7 @@
3134
"@types/mocha": "^5.0.0",
3235
"@types/sequelize": "^4.0.79",
3336
"axios": "^0.19.2",
34-
"chai": "^4.1.2",
37+
"chai": "^4.2.0",
3538
"mkdirp": "^0.5.1",
3639
"mocha": "^5.0.4",
3740
"nyc": "^12.0.1",
@@ -44,8 +47,8 @@
4447
"build": "tsc",
4548
"apidoc": "apidoc -i src -o docs",
4649
"prestart": "npm run build && npm run apidoc",
47-
"start": "cross-env NODE_PATH=dist scripts/wait-for-it.sh ${AMQP_HOST}:${AMQP_PORT} -- node dist/run.js",
48-
"test": "cross-env NODE_PATH=src node_modules/.bin/mocha --timeout 12000 --exit --require ts-node/register test/utils/setup*.ts test/*.ts",
50+
"start": "cross-env NODE_PATH=dist scripts/wait-for-it.sh localhost:5672 -- node dist/run.js",
51+
"test": "cross-env NODE_PATH=src NODE_ENV=test mocha --timeout 12000 --exit --require ts-node/register test/utils/setup*.ts test/unit/validators/*.ts test/e2e/*.ts",
4952
"cover": "nyc npm test",
5053
"seedlangs": "node dist/scripts/seed-defaultlangs.js",
5154
"precodecov": "npm run cover",

src/models/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as Sequelize from 'sequelize'
22
import * as path from 'path'
33
import * as fs from 'fs'
4-
import config = require('../../config')
54
import dbg = require('debug')
65

6+
const config = require('../../config/index');
77
const basename = path.basename(module.filename);
88
const db: any = {}
99
const dbModel = {}

src/rabbitmq/jobqueue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as amqp from 'amqplib/callback_api'
22
import { Channel, Connection } from 'amqplib/callback_api'
33
import { EventEmitter } from 'events'
44
const debug = require('debug')('judge:api:jobqueue')
5-
import config = require('../../config')
5+
const config = require('../../config/index')
66

77
export interface SubmissionJob {
88
id: number

src/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import app from './server'
2-
import config = require('../config')
32
import * as debug from 'debug'
43
import DB from 'models'
54

5+
const config = require('../config/index')
66
const log = debug('judge:api')
77

88
DB.sequelize.sync({})

src/utils/s3.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Minio = require('minio')
22
import v4 = require('uuid/v4')
33
import axios from 'axios'
4-
import config = require('../../config')
54

5+
const config = require('../../config/index')
66
const client = new Minio.Client({
77
endPoint: config.S3.endpoint,
88
port: +config.S3.port,

0 commit comments

Comments
 (0)