Skip to content

Commit

Permalink
Extend test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
NSeydoux committed Dec 10, 2024
1 parent c06034e commit 15788eb
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 163 deletions.
58 changes: 56 additions & 2 deletions src/common/getters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,14 +628,14 @@ describe("getters", () => {
});

describe("getCustomIntegers", () => {
it("gets an integer array value from an access request custom field", async () => {
it("gets an integer array value from an access grant custom field", async () => {
const customFields = [
{
key: new URL("https://example.org/ns/customInt"),
value: [1],
},
];
const gConsentRequest = await mockGConsentRequest({
const gConsentRequest = await mockGConsentGrant({
custom: customFields,
});
// This shows the typing of the return is correct.
Expand Down Expand Up @@ -716,6 +716,24 @@ describe("getters", () => {
expect(b).toEqual([true]);
});

it("does not collapse similar values", async () => {
const customFields = [
{
key: new URL("https://example.org/ns/customBoolean"),
value: [true, true, true],
},
];
const gConsentRequest = await mockGConsentRequest({
custom: customFields,
});
// This shows the typing of the return is correct.
const b: boolean[] = getCustomBooleans(
gConsentRequest,
new URL("https://example.org/ns/customBoolean"),
);
expect(b).toEqual([true, true, true]);
});

it("throws on mixed types", async () => {
const customFields = [
{
Expand Down Expand Up @@ -768,6 +786,24 @@ describe("getters", () => {
expect(d).toEqual([1.1]);
});

it("does not collapse similar values", async () => {
const customFields = [
{
key: new URL("https://example.org/ns/customFloat"),
value: [1.1, 1.1, 1.1],
},
];
const gConsentRequest = await mockGConsentRequest({
custom: customFields,
});
// This shows the typing of the return is correct.
const d: number[] = getCustomDoubles(
gConsentRequest,
new URL("https://example.org/ns/customFloat"),
);
expect(d).toEqual([1.1, 1.1, 1.1]);
});

it("throws on mixed types", async () => {
const customFields = [
{
Expand Down Expand Up @@ -820,6 +856,24 @@ describe("getters", () => {
expect(s).toEqual(["custom value"]);
});

it("does not collapse similar values", async () => {
const customFields = [
{
key: new URL("https://example.org/ns/customString"),
value: ["some value", "some value", "some value"],
},
];
const gConsentRequest = await mockGConsentRequest({
custom: customFields,
});
// This shows the typing of the return is correct.
const s: string[] = getCustomStrings(
gConsentRequest,
new URL("https://example.org/ns/customString"),
);
expect(s).toEqual(["some value", "some value", "some value"]);
});

it("throws on mixed types", async () => {
const customFields = [
{
Expand Down
Loading

0 comments on commit 15788eb

Please sign in to comment.