{"size": 1519, "ext": "js", "max_stars_repo_path": "test/controllers/api.spec.js", "max_stars_repo_name": "Jkat/wt-read-api", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/controllers/api.spec.js", "max_issues_repo_name": "Jkat/wt-read-api", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/controllers/api.spec.js", "max_forks_repo_name": "Jkat/wt-read-api", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.1896551724, "max_line_length": 83, "alphanum_fraction": 0.5464121132}
/* eslint-env mocha */
/* eslint-disable no-unused-expressions */
const { expect } = require('chai');
const request = require('supertest');
const config = require('../../src/config');

describe('API', function () {
  let server;
  beforeEach(() => {
    server = require('../../src/index');
  });
  afterEach(() => {
    server.close();
  });

  it('GET /', async () => {
    await request(server)
      .get('/')
      .expect((res) => {
        expect(res.body).to.have.property('docs');
        expect(res.body).to.have.property('info');
        expect(res.body).to.have.property('version');
        expect(res.body).to.have.property('config', process.env.WT_CONFIG);
        expect(res.body).to.have.property('wtIndexAddress', config.wtIndexAddress);
      })
      .expect(200);
  });

  it('should respond with CORS headers', async () => {
    await request(server)
      .get('/')
      .expect((res) => {
        expect(res.headers).to.have.property('access-control-allow-origin', '*');
      })
      .expect(200);
  });

  it('GET /docs', async () => {
    await request(server)
      .get('/docs/')
      .expect('content-type', /html/i)
      .expect((res) => {
        expect(res.text).to.not.be.empty;
      })
      .expect(200);
  });

  it('GET /random-endpoint', async () => {
    await request(server)
      .get('/random-endpoint')
      .expect('content-type', /json/i)
      .expect((res) => {
        expect(res.body).to.have.property('code', '#notFound');
      })
      .expect(404);
  });
});
