{"size": 1318, "ext": "js", "max_stars_repo_path": "class-04/demo/server/__tests__/server.test.js", "max_stars_repo_name": "RamiZregat/amman-javascript-401d13", "max_stars_repo_stars_event_min_datetime": "2021-11-08T11:42:40.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-16T10:40:06.000Z", "max_issues_repo_path": "class-04/demo/server/__tests__/server.test.js", "max_issues_repo_name": "RamiZregat/amman-javascript-401d13", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "class-04/demo/server/__tests__/server.test.js", "max_forks_repo_name": "RamiZregat/amman-javascript-401d13", "max_forks_repo_forks_event_min_datetime": "2021-10-31T12:00:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-13T21:12:46.000Z"}
{"max_stars_count": 4, "max_issues_count": null, "max_forks_count": 18, "avg_line_length": 31.380952381, "max_line_length": 85, "alphanum_fraction": 0.5827010622}
'use strict';
const server = require('../server');
// I do not have to run it
const supertest = require('supertest');
const request = supertest(server.app);

//add the name of the module that I am testing 
describe('my API Server', ()=> {

    beforeEach(()=> {
        jest.spyOn(console, 'log').mockImplementation();
    })

    // add scenarios & test cases 
    it('handles not found request', async () => {
        // add test
        const response = await request.get('/asd'); // async
        expect(response.status).toEqual(404);
    });

    //  1. callbacks ---> Promises (Promise.then() ) ----> Async/Await
    
    it('handles my internal server errors', async () => {
        const response = await request.post('/bad'); // async
        expect(response.status).toEqual(500);
    });
    
    it('get data from /data ', async () => {
        const response = await request.get('/data'); // async
        expect(response.status).toEqual(200);
        expect(typeof response.body).toEqual('object'); // superagent is behind this 
    });
    
    it('/ route works', async () => {
        const response = await request.get('/'); // async
        expect(response.status).toEqual(200);
        console.log(response.text);
        expect(response.text).toEqual('this is home page!!! :D :D :D');
    });


});