Skip to content

Commit

Permalink
Implement testing for featured packages, minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
confused-Techie committed Sep 26, 2023
1 parent 7b138ea commit 59f4399
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/controllers/deletePackagesPackageNameStar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

module.exports = {
docs: {
summary: "Unstar a package."
summary: "Unstar a package.",
responses: {
204: {
description: "An empty response, indicating success."
}
}
},
endpoint: {
method: "DELETE",
Expand Down
10 changes: 9 additions & 1 deletion src/controllers/getPackagesFeatured.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@

module.exports = {
docs: {
summary: "Returns all featured packages. Previously undocumented endpoint."
summary: "Returns all featured packages. Previously undocumented endpoint.",
responses: {
200: {
description: "An array of features packages.",
content: {
"application/json": "$packageObjectShortArray"
}
}
}
},
endpoint: {
method: "GET",
Expand Down
68 changes: 68 additions & 0 deletions tests/http/getPackagesFeatured.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const endpoint = require("../../src/controllers/getPackagesFeatured.js");
const database = require("../../src/database.js");
const context = require("../../src/context.js");

describe("Behaves as expected", () => {
test("Calls the correct function", async () => {
const localContext = context;
const spy = jest.spyOn(localContext.database, "getFeaturedPackages");

await endpoint.logic({}, localContext);

expect(spy).toBeCalledTimes(1);

spy.mockClear();
});

test("Returns not found with no packages present", async () => {
const sso = await endpoint.logic({}, context);

expect(sso.ok).toBe(false);
expect(sso.content.short).toBe("not_found");
});

test("Returns proper data on success", async () => {
const addPack = await database.insertNewPackage({

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note test

Unused variable addPack.
// We know a currently featured package is 'x-terminal-reloaded'
name: "x-terminal-reloaded",
repository: {
url: "https://github.com/Spiker985/x-terminal-reloaded",
type: "git"
},
creation_method: "Test Package",
releases: {
latest: "1.1.0"
},
readme: "This is a readme!",
metadata: {
name: "atom-material-ui"
},
versions: {
"1.1.0": {
dist: {
tarball: "download-url",
sha: "1234"
},
name: "x-terminal-reloaded"
},
"1.0.0": {
dist: {
tarball: "download-url",
sha: "1234"
},
name: "x-terminal-reloaded"
}
}
});

const sso = await endpoint.logic({}, context);

expect(sso.ok).toBe(true);
expect(sso.content).toBeArray();
expect(sso.content.length).toBe(1);
expect(sso.content[0].name).toBe("x-terminal-reloaded");
expect(sso).toMatchEndpointSuccessObject(endpoint);

await database.removePackageByName("x-terminal-reloaded", true);
});
});
2 changes: 1 addition & 1 deletion tests/models/packageObjectFullArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
},
example: [
require("./packageObjectFull.js").example
]
],
test:
Joi.array().items(
require("./packageObjectFull.js").test
Expand Down

0 comments on commit 59f4399

Please sign in to comment.