Skip to content

Commit

Permalink
Merge pull request #105 from pulsar-edit/simple-uninstall
Browse files Browse the repository at this point in the history
Remove Uninstallation Behavior
  • Loading branch information
confused-Techie authored Mar 2, 2023
2 parents 6ec1608 + 5a6eeda commit 6cb15ed
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 73 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

## [Unreleased]

* Deprecate `/api/packages/:packageName/versions/:versionName/events/uninstall`. This endpoint no longer has any effect, but will still return a successful query to avoid user impact.
* Refactored the existing testing platform
* Refactored all interactions with GitHub, Git, and provided the base system to support multiple VCS services in the future.

Expand Down
38 changes: 4 additions & 34 deletions src/handlers/package_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1017,47 +1017,17 @@ async function deletePackageVersion(req, res) {
* @desc Used when a package is uninstalled, decreases the download count by 1.
* And saves this data, Originally an undocumented endpoint.
* The decision to return a '201' was based on how other POST endpoints return,
* during a successful event.
* during a successful event. This endpoint has now been deprecated, as it serves
* no useful features, and on further examination may have been intended as a way
* to collect data on users, which is not something we implement.
* @deprecated since v 1.0.2
* @see {@link https://github.com/atom/apm/blob/master/src/uninstall.coffee}
* @param {object} req - The `Request` object inherited from the Express endpoint.
* @param {object} res - The `Response` object inherited from the Express endpoint.
* @property {http_method} - POST
* @property {http_endpoint} - /api/packages/:packageName/versions/:versionName/events/uninstall
*/
async function postPackagesEventUninstall(req, res) {
const params = {
auth: query.auth(req),
packageName: query.packageName(req),
// TODO: versionName unused parameter. On the roadmap to be removed.
// See https://github.com/confused-Techie/atom-backend/pull/88#issuecomment-1331809594
versionName: query.engine(req.params.versionName),
};

const user = await auth.verifyAuth(params.auth);

if (!user.ok) {
await common.handleError(req, res, user);
return;
}

// TODO: How does this impact performance? Wonder if we could return
// the next command with more intelligence to know the pack doesn't exist.
const packExists = await database.getPackageByName(params.packageName, true);

if (!packExists.ok) {
await common.handleError(req, res, packExists);
return;
}

const write = await database.updatePackageDecrementDownloadByName(
params.packageName
);

if (!write.ok) {
await common.handleError(req, res, write);
return;
}

res.status(200).json({ ok: true });
logger.httpLog(req, res);
}
Expand Down
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,7 @@ app.options(
* @ignore
* @path /api/packages/:packageName/versions/:versionName/events/uninstall
* @desc Previously undocumented endpoint. BETA: Decreases the packages download count, by one. Indicating an uninstall.
* v1.0.2 - Now has no effect. Being deprecated, but presents no change to end users.
* @method POST
* @auth true
* @param
Expand Down
44 changes: 5 additions & 39 deletions test/packages.handler.integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,43 +653,9 @@ describe("GET /api/packages/:packageName/versions/:versionName/tarball", () => {
});

describe("POST /api/packages/:packageName/versions/:versionName/events/uninstall", () => {
test.todo("Write all of these");
test("Returns 401 with No Auth", async () => {
const res = await request(app).post(
"/api/packages/language-css/versions/0.45.7/events/uninstall"
);
expect(res).toHaveHTTPCode(401);
});
test("Returns Bad Auth Message with No Auth", async () => {
const res = await request(app).post(
"/api/packages/langauge-css/versions/0.45.7/events/uninstall"
);
expect(res.body.message).toEqual(msg.badAuth);
});
test("Returns 401 with Bad Auth", async () => {
const res = await request(app)
.post("/api/packages/language-css/versions/0.45.7/events/uninstall")
.set("Authorization", "invalid");
expect(res).toHaveHTTPCode(401);
});
test("Returns Bad Auth Message with No Auth", async () => {
const res = await request(app)
.post("/api/packages/langauge-css/versions/0.45.7/events/uninstall")
.set("Authorization", "invalid");
expect(res.body.message).toEqual(msg.badAuth);
});
test("Returns 404 with Bad Package", async () => {
const res = await request(app)
.post("/api/packages/language-golang/versions/1.0.0/events/uninstall")
.set("Authorization", "valid-token");
expect(res).toHaveHTTPCode(404);
});
test("Returns Not Found Message with Bad Package", async () => {
const res = await request(app)
.post("/api/packages/language-golang/versions/1.0.0/events/uninstall")
.set("Authorization", "valid-token");
expect(res.body.message).toEqual(msg.notFound);
});
// This endpoint is now being deprecated, so we will remove tests
// for handling any kind of actual functionality.
// Instead ensuring this returns as success to users are unaffected.
test("Returns 200 with Valid Package, Bad Version", async () => {
const res = await request(app)
.post("/api/packages/language-css/versions/1.0.0/events/uninstall")
Expand Down Expand Up @@ -718,13 +684,13 @@ describe("POST /api/packages/:packageName/versions/:versionName/events/uninstall
.set("Authorization", "valid-token");
expect(res.body.ok).toBeTruthy();
});
test("Properly decrements the download count", async () => {
test("After deprecating endpoint, ensure the endpoint has no effect", async () => {
const orig = await request(app).get("/api/packages/language-css");
const res = await request(app)
.post("/api/packages/language-css/versions/0.45.7/events/uninstall")
.set("Authorization", "valid-token");
const after = await request(app).get("/api/packages/language-css");
expect(parseInt(orig.body.downloads, 10)).toBeGreaterThan(
expect(parseInt(orig.body.downloads, 10)).toEqual(
parseInt(after.body.downloads, 10)
);
});
Expand Down

0 comments on commit 6cb15ed

Please sign in to comment.