Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Uninstallation Behavior #105

Merged
merged 2 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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