Skip to content

Commit

Permalink
Break up request adjudicator tests to separate file for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
samayer12 committed Nov 8, 2024
1 parent 29d1c8f commit 2756e97
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 89 deletions.
89 changes: 0 additions & 89 deletions src/lib/filter/adjudicators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -884,26 +884,6 @@ describe("operationMatchesEvent", () => {
});
});

describe("declaredOperation", () => {
//[ AdmissionRequest, result ]
it.each([
[{}, ""],
[{ operation: null }, ""],
[{ operation: "" }, ""],
[{ operation: "operation" }, "operation"],
[{ operation: Operation.CONNECT }, Operation.CONNECT],
[{ operation: Operation.CREATE }, Operation.CREATE],
[{ operation: Operation.UPDATE }, Operation.UPDATE],
[{ operation: Operation.DELETE }, Operation.DELETE],
])("given %j, returns '%s'", (given, expected) => {
const request = given as DeepPartial<AdmissionRequest>;

const result = sut.declaredOperation(request);

expect(result).toEqual(expected);
});
});

describe("mismatchedEvent", () => {
//[ Binding, AdmissionRequest, result ]
it.each([
Expand Down Expand Up @@ -980,24 +960,6 @@ describe("definesGroup", () => {
});
});

describe("declaredGroup", () => {
//[ AdmissionRequest, result ]
it.each([
[{}, ""],
[{ kind: null }, ""],
[{ kind: {} }, ""],
[{ kind: { group: null } }, ""],
[{ kind: { group: "" } }, ""],
[{ kind: { group: "group" } }, "group"],
])("given %j, returns '%s'", (given, expected) => {
const request = given as DeepPartial<AdmissionRequest>;

const result = sut.declaredGroup(request);

expect(result).toEqual(expected);
});
});

describe("mismatchedGroup", () => {
//[ Binding, AdmissionRequest, result ]
it.each([
Expand Down Expand Up @@ -1052,24 +1014,6 @@ describe("definesVersion", () => {
});
});

describe("declaredVersion", () => {
//[ AdmissionRequest, result ]
it.each([
[{}, ""],
[{ kind: null }, ""],
[{ kind: {} }, ""],
[{ kind: { version: null } }, ""],
[{ kind: { version: "" } }, ""],
[{ kind: { version: "version" } }, "version"],
])("given %j, returns '%s'", (given, expected) => {
const request = given as DeepPartial<AdmissionRequest>;

const result = sut.declaredVersion(request);

expect(result).toEqual(expected);
});
});

describe("mismatchedVersion", () => {
//[ Binding, AdmissionRequest, result ]
it.each([
Expand Down Expand Up @@ -1124,24 +1068,6 @@ describe("definesKind", () => {
});
});

describe("declaredKind", () => {
//[ AdmissionRequest, result ]
it.each([
[{}, ""],
[{ kind: null }, ""],
[{ kind: {} }, ""],
[{ kind: { kind: null } }, ""],
[{ kind: { kind: "" } }, ""],
[{ kind: { kind: "kind" } }, "kind"],
])("given %j, returns '%s'", (given, expected) => {
const request = given as DeepPartial<AdmissionRequest>;

const result = sut.declaredKind(request);

expect(result).toEqual(expected);
});
});

describe("mismatchedKind", () => {
//[ Binding, AdmissionRequest, result ]
it.each([
Expand Down Expand Up @@ -1220,18 +1146,3 @@ describe("definedCallbackName", () => {
expect(result).toEqual(expected);
});
});

describe("declaredUid", () => {
//[ AdmissionRequest, result ]
it.each([
[{}, ""],
[{ uid: null }, ""],
[{ uid: "uid" }, "uid"],
])("given %j, returns '%s'", (given, expected) => {
const request = given as DeepPartial<AdmissionRequest>;

const result = sut.declaredUid(request);

expect(result).toEqual(expected);
});
});
96 changes: 96 additions & 0 deletions src/lib/filter/adjudicators/requestAdjudicators.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors

import { expect, describe, it } from "@jest/globals";
import * as sut from "../adjudicators";
import { AdmissionRequest, DeepPartial } from "../../types";
import { Operation } from "../../enums";

describe("declaredUid", () => {
//[ AdmissionRequest, result ]
it.each([
[{}, ""],
[{ uid: null }, ""],
[{ uid: "uid" }, "uid"],
])("given %j, returns '%s'", (given, expected) => {
const request = given as DeepPartial<AdmissionRequest>;

const result = sut.declaredUid(request);

expect(result).toEqual(expected);
});
});

describe("declaredKind", () => {
//[ AdmissionRequest, result ]
it.each([
[{}, ""],
[{ kind: null }, ""],
[{ kind: {} }, ""],
[{ kind: { kind: null } }, ""],
[{ kind: { kind: "" } }, ""],
[{ kind: { kind: "kind" } }, "kind"],
])("given %j, returns '%s'", (given, expected) => {
const request = given as DeepPartial<AdmissionRequest>;

const result = sut.declaredKind(request);

expect(result).toEqual(expected);
});
});

describe("declaredVersion", () => {
//[ AdmissionRequest, result ]
it.each([
[{}, ""],
[{ kind: null }, ""],
[{ kind: {} }, ""],
[{ kind: { version: null } }, ""],
[{ kind: { version: "" } }, ""],
[{ kind: { version: "version" } }, "version"],
])("given %j, returns '%s'", (given, expected) => {
const request = given as DeepPartial<AdmissionRequest>;

const result = sut.declaredVersion(request);

expect(result).toEqual(expected);
});
});

describe("declaredGroup", () => {
//[ AdmissionRequest, result ]
it.each([
[{}, ""],
[{ kind: null }, ""],
[{ kind: {} }, ""],
[{ kind: { group: null } }, ""],
[{ kind: { group: "" } }, ""],
[{ kind: { group: "group" } }, "group"],
])("given %j, returns '%s'", (given, expected) => {
const request = given as DeepPartial<AdmissionRequest>;

const result = sut.declaredGroup(request);

expect(result).toEqual(expected);
});
});

describe("declaredOperation", () => {
//[ AdmissionRequest, result ]
it.each([
[{}, ""],
[{ operation: null }, ""],
[{ operation: "" }, ""],
[{ operation: "operation" }, "operation"],
[{ operation: Operation.CONNECT }, Operation.CONNECT],
[{ operation: Operation.CREATE }, Operation.CREATE],
[{ operation: Operation.UPDATE }, Operation.UPDATE],
[{ operation: Operation.DELETE }, Operation.DELETE],
])("given %j, returns '%s'", (given, expected) => {
const request = given as DeepPartial<AdmissionRequest>;

const result = sut.declaredOperation(request);

expect(result).toEqual(expected);
});
});

0 comments on commit 2756e97

Please sign in to comment.