{"size": 2370, "ext": "js", "max_stars_repo_path": "test/folder/root/get.test.js", "max_stars_repo_name": "romedu/multi-todo-api", "max_stars_repo_stars_event_min_datetime": "2020-01-19T18:56:35.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-19T18:56:35.000Z", "max_issues_repo_path": "test/folder/root/get.test.js", "max_issues_repo_name": "romedu/multi-todo-api", "max_issues_repo_issues_event_min_datetime": "2020-01-08T03:43:10.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-08T03:43:10.000Z", "max_forks_repo_path": "test/folder/root/get.test.js", "max_forks_repo_name": "romedu/multi-todo-api", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 26.6292134831, "max_line_length": 91, "alphanum_fraction": 0.6219409283}
const request = require("supertest"),
	app = require("../../../src/app"),
	{ createTestUser } = require("../../utilities"),
	{ folderBaseUrl } = require("../../urls");

describe("GET /folder", () => {
	let userData, authorizationToken;

	beforeAll(async () => {
		const testUserCredentials = {
			username: "folderGetTestUser",
			password: "folderGetTestPw"
		};

		userData = await createTestUser(testUserCredentials);
		authorizationToken = userData.token;
	});

	describe("Authorized requests", () => {
		describe("Get request", () => {
			const paginatedFoldersSchema = {
				docs: expect.any(Array),
				total: expect.any(Number),
				limit: expect.any(Number)
			};

			describe("Passing a valid limit query param", () => {
				const queryParams = { limit: 10 };

				let response;

				beforeAll(async () => {
					response = await request(app)
						.get(folderBaseUrl)
						.query(queryParams)
						.set("Authorization", authorizationToken);
				});

				it("should return a status of 200", () => {
					expect(response.status).toBe(200);
				});

				it("should return a paginated folders object", () => {
					expect(response.body).toEqual(expect.objectContaining(paginatedFoldersSchema));
				});

				it("should return with a limit property with the same value as the one passed", () => {
					expect(response.body.limit).toBe(queryParams.limit);
				});
			});

			describe("Passing an invalid limit query param", () => {
				const queryParams = { limit: "invalid limit" };

				let response;

				beforeAll(async () => {
					response = await request(app)
						.get(folderBaseUrl)
						.query(queryParams)
						.set("Authorization", authorizationToken);
				});

				it("should return a status of 200", () => {
					expect(response.status).toBe(200);
				});

				it("should return a paginated folders object", () => {
					expect(response.body).toEqual(expect.objectContaining(paginatedFoldersSchema));
				});

				it("should return with a limit property equal to it's default value", () => {
					expect(response.body.limit).not.toBe(queryParams.limit);
				});
			});
		});
	});

	describe("Unauthorized requests", () => {
		describe("Get request", () => {
			it("should return a status of 401", async done => {
				const response = await request(app).get(folderBaseUrl);
				expect(response.status).toBe(401);
				done();
			});
		});
	});
});
