import supertest from 'supertest';
import { server, createTestUser, logInUser, id } from '../helpers';

describe('GET /auth/current-user', () => {
  it('should return 403 if user is not logged in', async () => {
    const res = await supertest(server).get('/api/v1/auth/current-user').send();

    expect(res.status).toBe(403);
  });

  it('should return 404 if user is not found', async () => {
    const res = await supertest(server)
      .get('/api/v1/auth/current-user')
      .set('Authorization', await logInUser())
      .send();

    expect(res.status).toBe(404);
    expect(res.body).toMatchObject({
      success: false,
      message: 'User account does not existing',
    });
  });

  it('should return 200 and correct data', async () => {
    const userId = id();
    await createTestUser({ _id: userId });

    const res = await supertest(server)
      .get('/api/v1/auth/current-user')
      .set('Authorization', await logInUser({ _id: userId }))
      .send();

    expect(res.status).toBe(200);
    expect(res.body).toMatchObject({
      success: true,
      message: 'get profile successful',
      data: expect.any(Object),
    });
  });
});
