forked from confused-Techie/atom-backend
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testing for
getPackagesPackageName
integrate Joi for testing object…
… structures
- Loading branch information
1 parent
37def97
commit c74f305
Showing
11 changed files
with
226 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
const endpoint = require("../../src/controllers/getPackagesPackageName.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, "getPackageByName"); | ||
|
||
await endpoint.logic({}, localContext); | ||
|
||
expect(spy).toBeCalledTimes(1); | ||
|
||
spy.mockClear(); | ||
}); | ||
|
||
test("Returns 'not_found' when package doesn't exist", async () => { | ||
const sso = await endpoint.logic({ | ||
engine: false, | ||
packageName: "anything" | ||
}, context); | ||
|
||
expect(sso.ok).toBe(false); | ||
expect(sso.content.short).toBe("not_found"); | ||
}); | ||
|
||
test("Returns package on success", async () => { | ||
await database.insertNewPackage({ | ||
name: "get-package-test", | ||
repository: { | ||
url: "https://github.com/confused-Techie/package-backend", | ||
type: "git" | ||
}, | ||
creation_method: "Test Package", | ||
releases: { | ||
latest: "1.1.0" | ||
}, | ||
readme: "This is a readme!", | ||
metadata: { | ||
name: "get-package-test" | ||
}, | ||
versions: { | ||
"1.1.0": { | ||
dist: { | ||
tarball: "download-url", | ||
sha: "1234" | ||
}, | ||
name: "get-package-test" | ||
}, | ||
"1.0.0": { | ||
dist: { | ||
tarball: "download-url", | ||
sha: "1234" | ||
}, | ||
name: "get-package-test" | ||
} | ||
} | ||
}); | ||
|
||
const sso = await endpoint.logic({ | ||
engine: false, | ||
packageName: "get-package-test" | ||
}, context); | ||
|
||
expect(sso.ok).toBe(true); | ||
expect(sso.content.name).toBe("get-package-test"); | ||
expect(sso).toMatchEndpointSuccessObject(endpoint); | ||
await database.removePackageByName("get-package-test", true); | ||
}); | ||
|
||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
module.exports = { | ||
schema: { | ||
description: "A 'Package Object Full' of a package on the PPR.", | ||
type: "object", | ||
required: [ | ||
"name", "readme", "metadata", "releases", "versions", | ||
"repository", "creation_method", "downloads", "stargazers_count", "badges" | ||
], | ||
properties: { | ||
name: { type: "string" }, | ||
readme: { type: "string" }, | ||
metadata: { type: "object" }, | ||
releases: { type: "object" }, | ||
versions: { type: "object" }, | ||
repository: { type: "object" }, | ||
creation_method: { type: "string" }, | ||
downloads: { type: "string" }, | ||
stargazers_count: { type: "string" }, | ||
badges: { type: "array" } | ||
} | ||
}, | ||
example: { | ||
// This is nearly the full return of `language-powershell-revised` | ||
name: "language-powershell-revised", | ||
readme: "This is the full content of a readme file!", | ||
metadata: { | ||
// The metadata field is the `package.json` of the most recent version | ||
// With the `dist` object added | ||
dist: { | ||
sha: "604a047247ded9df50e7325345405c93871868e5", | ||
tarball: "https://api.github.com/repos/confused-Techie/language-powershell-revised/tarball/refs/tags/v1.0.0" | ||
}, | ||
name: "language-powershell-revised", | ||
engines: { | ||
atom: ">=1.0.0 <2.0.0" | ||
}, | ||
license: "MIT", | ||
version: "1.0.0", | ||
keywords: [], | ||
// This may be a repository object | ||
repository: "https://github.com/confused-Techie/language-powershell-revised", | ||
description: "Updated, revised PowerShell Syntax Highlighting Support in Pulsar." | ||
}, | ||
releases: { | ||
latest: "1.0.0" | ||
}, | ||
versions: { | ||
"1.0.0": { | ||
// This is the `package.json` of every version | ||
// With a `dist` key added | ||
dist: { | ||
tarball: "https://api.pulsar-edit.dev/api/packages/language-powershell-revised/versions/1.0.0/tarball" | ||
}, | ||
name: "language-powershell-revised", | ||
engines: { | ||
atom: ">=1.0.0 <2.0.0" | ||
}, | ||
license: "MIT", | ||
version: "1.0.0", | ||
keywords: [], | ||
repository: "https://github.com/confsued-Techie/language-powershell-revised", | ||
description: "Updated, revised PowerShell Syntax Highlighting Support in Pulsar" | ||
} | ||
}, | ||
repository: { | ||
// This is the repo object for the VCS Service | ||
url: "https://github.com/confsued-Techie/langauge-powershell-revised", | ||
type: "git" | ||
}, | ||
// This can be either `User Made Package` or `Migrated Package` | ||
creation_method: "User Made Package", | ||
// Note how some fields here are strings not numbers | ||
downloads: "54", | ||
stargazers_count: "0", | ||
badges: [ | ||
// Some badges are baked in, some are applied at render time. | ||
{ | ||
title: "Made for Pulsar!", | ||
type: "success" | ||
} | ||
] | ||
}, | ||
test: | ||
Joi.object({ | ||
name: Joi.string().required(), | ||
readme: Joi.string().required(), | ||
metadata: Joi.object().required(), | ||
releases: Joi.object().required(), | ||
versions: Joi.object().required(), | ||
repository: Joi.object().required(), | ||
creation_method: Joi.string().required(), | ||
downloads: Joi.string().required(), | ||
stargazers_count: Joi.string().required(), | ||
badges: Joi.array().items( | ||
Joi.object({ | ||
title: Joi.string().valid( | ||
"Outdated", | ||
"Made for Pulsar!", | ||
"Broken", | ||
"Archived", | ||
"Deprecated" | ||
).required(), | ||
type: Joi.string().valid( | ||
"warn", "info", "success" | ||
).required(), | ||
text: Joi.string(), | ||
link: Joi.string() | ||
}) | ||
).required() | ||
}) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters