coding-blocks / judge-api

7 stars 27 forks source link

Write tests #58

Closed jatinkatyal13 closed 4 years ago

jatinkatyal13 commented 4 years ago

Since we have added more features to the application we need to update our tests as well

r0cketr1kky commented 4 years ago

Hi @jatinkatyal13 , I would like to work on this issue for BOSS. Could you assign me this?

jatinkatyal13 commented 4 years ago

@r0cketr1kky Sure you can go ahead and attempt this.

atmanandsah commented 4 years ago

Hi @jatinkatyal13 , I would also work on this can you pls open for me also ?

jatinkatyal13 commented 4 years ago

@atmanandsah sure, go ahead and I'm here for any doubts

atmanandsah commented 4 years ago

sure, @jatinkatyal13 for this i have to configure https://github.com/coding-blocks/judge-api.git. And for running judge-api i have to configure the PostgreSQL database?

jatinkatyal13 commented 4 years ago

yup setting up postgres is required but docker would help

atmanandsah commented 4 years ago

hey @jatinkatyal13 i created the codingblocks/judge-api image and how to create the postgres image is my right way to configure the project?

jatinkatyal13 commented 4 years ago

docker-compose pull should do the trick

atmanandsah commented 4 years ago

yeah done but i still unbale to run npm run test. i installed the ts-node also .

Error judge-api@1.2.0 test C:\Users\sonu\Desktop\coding blocks\judge-api

NODE_PATH=src node_modules/.bin/mocha --timeout 12000 --exit --require ts-node/register test/utils/setup.ts test/.ts

'NODE_PATH' is not recognized as an internal or external command, operable program or batch file. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! judge-api@1.2.0 test: NODE_PATH=src node_modules/.bin/mocha --timeout 12000 --exit --require ts-node/register test/utils/setup*.ts test/*.ts npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the judge-api@1.2.0 test script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\sonu\AppData\Roaming\npm-cache_logs\2020-05-11T09_11_37_803Z-debug.log

atmanandsah commented 4 years ago

@jatinkatyal13 bhaiya pls look into this

jatinkatyal13 commented 4 years ago

@atmanandsah should work now

atmanandsah commented 4 years ago

@jatinkatyal13 bhaiya still getting the error have a look.

cross-env NODE_PATH=src node_modules/.bin/mocha --timeout 12000 --exit --require ts-node/register test/utils/setup.ts test/.ts

'cross-env' is not recognized as an internal or external command, operable program or batch file. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! judge-api@1.2.0 test: cross-env NODE_PATH=src node_modules/.bin/mocha --timeout 12000 --exit --require ts-node/register test/utils/setup*.ts test/*.ts npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the judge-api@1.2.0 test script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\sonu\AppData\Roaming\npm-cache_logs\2020-05-11T13_26_33_046Z-debug.log

jatinkatyal13 commented 4 years ago

There is a new dependency, run yarn install again

atmanandsah commented 4 years ago

@jatinkatyal13 bhaiya after installing yarn dependencies and npm run test the error looks scary have a look.

cross-env NODE_PATH=src node_modules/.bin/mocha --timeout 12000 --exit --require ts-node/register test/utils/setup.ts test/.ts

sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators node_modules\sequelize\lib\sequelize.js:245:13

C:\Users\sonu\Desktop\coding blocks\judge-api\node_modules\ts-node\src\index.ts:421 return new TSError(diagnosticText, diagnosticCodes) ^ TSError: ⨯ Unable to compile TypeScript: test/api.langs.spec.ts:1:26 - error TS2307: Cannot find module 'request'.

1 import * as request from 'request'

test/api.langs.spec.ts:6:27 - error TS2307: Cannot find module 'request'.

6 import {CoreOptions} from 'request'
at createTSError (C:\Users\sonu\Desktop\coding blocks\judge-api\node_modules\ts-node\src\index.ts:421:12)        
at reportTSError (C:\Users\sonu\Desktop\coding blocks\judge-api\node_modules\ts-node\src\index.ts:425:19)        
at getOutput (C:\Users\sonu\Desktop\coding blocks\judge-api\node_modules\ts-node\src\index.ts:530:36)
at Object.compile (C:\Users\sonu\Desktop\coding blocks\judge-api\node_modules\ts-node\src\index.ts:735:32)       
at Module.m._compile (C:\Users\sonu\Desktop\coding blocks\judge-api\node_modules\ts-node\src\index.ts:814:43)    
at Module._extensions..js (internal/modules/cjs/loader.js:991:10)
at Object.require.extensions.<computed> [as .ts] (C:\Users\sonu\Desktop\coding blocks\judge-api\node_modules\ts-node\src\index.ts:817:12)
at Module.load (internal/modules/cjs/loader.js:811:32)
at Function.Module._load (internal/modules/cjs/loader.js:723:14)
at Module.require (internal/modules/cjs/loader.js:848:19)
at require (internal/modules/cjs/helpers.js:74:18)
at C:\Users\sonu\Desktop\coding blocks\judge-api\node_modules\mocha\lib\mocha.js:250:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (C:\Users\sonu\Desktop\coding blocks\judge-api\node_modules\mocha\lib\mocha.js:247:14)        
at Mocha.run (C:\Users\sonu\Desktop\coding blocks\judge-api\node_modules\mocha\lib\mocha.js:576:10)
at Object.<anonymous> (C:\Users\sonu\Desktop\coding blocks\judge-api\node_modules\mocha\bin\_mocha:637:18)       
at Module._compile (internal/modules/cjs/loader.js:955:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
at Module.load (internal/modules/cjs/loader.js:811:32)
at Function.Module._load (internal/modules/cjs/loader.js:723:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! judge-api@1.2.0 test: cross-env NODE_PATH=src node_modules/.bin/mocha --timeout 12000 --exit --require ts-node/register test/utils/setup*.ts test/*.ts npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the judge-api@1.2.0 test script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\sonu\AppData\Roaming\npm-cache_logs\2020-05-11T13_40_13_543Z-debug.log

atmanandsah commented 4 years ago

@jatinkatyal13 bhaiya error from node modules ts-node pls help into this.

jatinkatyal13 commented 4 years ago

@atmanandsah these are the errors that needs to be fixed in this task 😄

atmanandsah commented 4 years ago

@jatinkatyal13 bhaiya i fix the sequelizer error using operatorsAliases: false in the index.ts src\models. bhaiya pls guide me in this one request module can I know the work of request model here ?

TSError: ⨯ Unable to compile TypeScript:
test/api.langs.spec.ts:1:21 - error TS2307: Cannot find module 'request'.
atmanandsah commented 4 years ago

@jatinkatyal13 bhaiya pls help into this.

jatinkatyal13 commented 4 years ago

@atmanandsah You can completely remove the request package as it is deprecated and not needed. As specified we need to use chai-http to perform the request inside our tests.

atmanandsah commented 4 years ago

@jatinkatyal13 bhaiya the error is due to the request module below is the code in api.langs.spec.ts

import { CoreOptions } from 'request';
jatinkatyal13 commented 4 years ago

@jatinkatyal13 bhaiya the error is due to the request module below is the code in api.langs.spec.ts

import { CoreOptions } from 'request';

We don't need the request package and that's the task to update the tests

prabalsingh24 commented 4 years ago

@jatinkatyal13 Why isn't here a case for 'poll', Shouldn't there be a case for 'poll' where the result is saved in the database, so that it can be fetched later by polling.

Also speaking of polling, why isn't there an endpoint for polling? Shouldn't there be an endpoint so that client can get the result later? Am I making sense or did I get this polling method completely wrong?

jatinkatyal13 commented 4 years ago

@prabalsingh24 In the case of polling the action is performed by the user. Hence, we only need to update the submissions model, and the rest of it will be done by the client. Yes, the endpoint for polling is a TODO, I'll be creating another issue under BOSS to create this endpoint once the tests are written.

Nice observation 🚀 !

PS: I've updated the method where the result is saved in the database which was not being done in the RunScenario.

YashKumarVerma commented 4 years ago

@jatinkatyal13 could you please expand this a bit more ? Since there will be no consumers on the other end of the queue, we will have to call onSuccess method on the controllers manually using setTimeout function with the mock result and assert it with the response from the API

jatinkatyal13 commented 4 years ago

@YashKumarVerma whenever we receive a request on the API we do 2 things

  1. create submission object in DB
  2. push the payload in the broker (Rabbitmq)

judge-taskmaster acts as the consumer in the queue and uses the payload to generate the result. Once the result is generated it pushed it on the success-queue. The api consumes on the success queue and sends the payload to the onSuccess handler

In the test we need to call this handler manually