import { Test, TestingModule } from "@nestjs/testing";
import { INestApplication } from "@nestjs/common";
import { SearchModule } from "src/infrastructure/modules/search.module";
import request from 'supertest'
import { assert } from "console";
import { resolve } from "path";
import { AppModule } from "src/infrastructure/modules";

describe('E2E Testing of /papers', () => {
    let app: INestApplication;

    beforeAll(async () => {
        const moduleRef: TestingModule = await Test.createTestingModule({
            imports: [AppModule],
        }).compile();

        app = moduleRef.createNestApplication();
        await app.init();
    });
    
    it('Should return one, exact item on page', async () => {
        return request(app.getHttpServer())
            .get('/papers/eeeb2d01-8315-454e-b33f-3d6caa25db42')
            .expect(200)
            .expect((res) => {
                res.body.data.length === 1;
            })
            .expect((res) => {
                res.body.data[0]._source.id === 'eeeb2d01-8315-454e-b33f-3d6caa25db42';
            });
    });

    it('Should return multiple items', async () => {
        return request(app.getHttpServer())
            .get('/papers/search?query=at&page=1')
            .expect(200)
            .expect((res) => {
                res.body.data.length > 0;
            })
            .expect((res) => {
                for (const value of res.body.data) {
                    if(Object.keys(value).length === 0) return false;
                }
            })
    });

    afterAll(async () => {
        await app.close();
    })
});