Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
confused-Techie committed Jan 20, 2024
1 parent 60f6be5 commit 21b8d89
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/unit/controllers/getStars.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe("Returns as expected", () => {
return { ok: true, content: {} };
},
};
localContext.utils = {
localContext.models = {
constructPackageObjectShort: () => {
return { item: "is_a_package" };
},
Expand Down
64 changes: 64 additions & 0 deletions tests/unit/models/constructPackageObjectFull.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const pof = require("../../../src/models/constructPackageObjectFull.js");
const schema = require("../../models/packageObjectFull.js").test;

describe("Parses Data, as expected to be returned by the Database", () => {

test("Correctly Parses normal data", async () => {
const data = {
pointer: "1234",
name: "test-package",
created: "2024-01-20T00:47:00.981Z",
updated: "2024-01-20T00:47:00.981Z",
creation_method: "Test Package",
downloads: "25",
data: {
name: "test-package",
owner: "pulsar-edit",
readme: "This is a readme!",
metadata: {
name: "test-package",
license: "MIT",
version: "1.0.0"
},
releases: { latest: "1.0.0" },
versions: {
"1.0.0": {
sha: "1234",
name: "test-package",
version: "1.0.0",
tarball_url: "https://nowhere.com"
}
},
repository: {
url: "https://github.com/pulsar-edit/test-package",
type: "git"
},
creation_method: "Test Package"
},
owner: "pulsar-edit",
stargazers_count: "1",
versions: [
{
id: 10,
meta: {
sha: "1234",
name: "test-package",
version: "1.0.0",
tarball_url: "https://nowhere.com"
},
engine: { atom: "*" },
semver: "1.0.0",
license: "MIT",
package: "1234",
hasGrammar: false,
hasSnippets: false,
supportedLanguages: null
}
]
};

const parsed = await pof(data);

expect(parsed).toMatchSchema(schema);
});
});
23 changes: 23 additions & 0 deletions tests/unit/models/constructPackageObjectJSON.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const poj = require("../../../src/models/constructPackageObjectJSON.js");
const schema = require("../../models/packageObjectJSON.js").test;

describe("Parses Data, as expected to be returned by the Database", () => {

test("Correctly Parses normal data", async () => {
const data = {
semver: "1.0.0",
license: "MIT",
engines: { atom: "*" },
meta: {
sha: "1234",
name: "package-test",
version: "1.0.0",
tarball_url: "https://nowhere.com"
}
};

const parsed = await poj(data);

expect(parsed).toMatchSchema(schema);
});
});
46 changes: 46 additions & 0 deletions tests/unit/models/constructPackageObjectShort.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const pos = require("../../../src/models/constructPackageObjectShort.js");
const schema = require("../../models/packageObjectShort.js").test;

describe("Parses Data, as expected to be returned by the Database", () => {

test("Correctly Parses normal data", async () => {
const data = {
name: "test-package",
data: {
name: "test-package",
owner: "pulsar-edit",
readme: "This is a readme!",
metadata: {
name: "test-package",
license: "MIT",
version: "1.0.0"
},
releases: { latest: "1.0.0" },
versions: {
"1.0.0": {
sha: "1234",
name: "test-package",
version: "1.0.0",
tarball_url: "https://nowhere.com"
}
},
repository: {
url: "https://github.com/pulsar-edit/test-package",
type: "git"
},
creation_method: "Test Package"
},
downloads: "0",
owner: "pulsar-edit",
stargazers_count: "0",
semver: "1.0.0",
created: "2024-01-20T00:46:57.014Z",
updated: "2024-01-20T00:46:57.014Z",
creation_method: "Test Package"
};

const parsed = await pos(data);

expect(parsed).toMatchSchema(schema);
});
});

0 comments on commit 21b8d89

Please sign in to comment.