const
	should = require('should'),
	rewire = require('rewire'),
	errors = require('booster/errors'),

	userRoutes = rewire('./user');

describe('User Routes', () => {
	describe('getLoggedInUser', () => {
		describe('when logged in', () => {
			it('should set the body to current user and the status to 200', async () => {
				const
					ctx = {state: {user: 123}};

				await userRoutes.getLoggedInUser(ctx);

				should.exist(ctx.body);
				should(ctx.body).equal(123);
				should.exist(ctx.status);
				should(ctx.status).equal(200);
			});
		});

		describe('when logged out', () => {
			it('should throw a notFound error', async () => {
				let err;
				const
					ctx = {state: {}};

				try {
					await userRoutes.getLoggedInUser(ctx);
				} catch(e) {
					err = e;
				}

				should.exist(err);
				should(err).be.an.instanceof(errors.notFound);
			});
		});
	});
});
