Skip to content
Draft
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
156 changes: 156 additions & 0 deletions packages/schemas/__tests__/ape-keys.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import { it, expect, describe } from "vitest";
import {
ApeKeyNameSchema,
ApeKeyUserDefinedSchema,
ApeKeySchema,
ApeKeysSchema,
} from "../src/ape-keys";

describe("ape-keys schemas", () => {
describe("ApeKeyNameSchema", () => {
it.each([
{
description: "valid slug within max length",
input: "my-ape-key",
},
{
description: "exceeds max length",
input: "this-name-is-way-too-long-for-schema",
expectedError: "String must contain at most 20 character",
},
] as const)("$description", ({ input, expectedError }) => {
if (expectedError) {
expect(ApeKeyNameSchema).toReject(input, expectedError);
} else {
expect(ApeKeyNameSchema).toValidate(input);
}
});
});

describe("ApeKeyUserDefinedSchema", () => {
it.each([
{
description: "minimal valid user-defined ape key",
input: {
name: "test-key",
enabled: true,
},
},
{
description: "missing name",
input: { enabled: false },
expectedError: "Required",
},
{
description: "missing enabled",
input: { name: "test-key" },
expectedError: "Required",
},
] as const)("$description", ({ input, expectedError }) => {
if (expectedError) {
expect(ApeKeyUserDefinedSchema).toReject(input, expectedError);
} else {
expect(ApeKeyUserDefinedSchema).toValidate(input);
}
});
});

describe("ApeKeySchema", () => {
it.each([
{
description: "minimal valid ape key",
input: {
name: "test-key",
enabled: true,
createdOn: 0,
modifiedOn: 0,
lastUsedOn: 0,
},
},
{
description: "lastUsedOn is -1",
input: {
name: "test-key",
enabled: false,
createdOn: 1234567890,
modifiedOn: 1234567890,
lastUsedOn: -1,
},
},
{
description: "missing createdOn",
input: {
name: "test-key",
enabled: true,
modifiedOn: 0,
lastUsedOn: 0,
},
expectedError: "Required",
},
{
description: "createdOn negative",
input: {
name: "test-key",
enabled: true,
createdOn: -1,
modifiedOn: 0,
lastUsedOn: 0,
},
expectedError: "Number must be greater than or equal to 0",
},
{
description: "lastUsedOn negative and not -1",
input: {
name: "test-key",
enabled: true,
createdOn: 0,
modifiedOn: 0,
lastUsedOn: -2,
},
expectedError: "Number must be greater than or equal to 0",
},
] as const)("$description", ({ input, expectedError }) => {
if (expectedError) {
expect(ApeKeySchema).toReject(input, expectedError);
} else {
expect(ApeKeySchema).toValidate(input);
}
});
});

describe("ApeKeysSchema", () => {
it.each([
{
description: "valid record of ape keys",
input: {
key1: {
name: "test-key",
enabled: true,
createdOn: 0,
modifiedOn: 0,
lastUsedOn: 0,
},
},
},
{
description: "invalid value in record",
input: {
key1: {
name: "test-key",
enabled: true,
createdOn: -1,
modifiedOn: 0,
lastUsedOn: 0,
},
},
expectedError: "Number must be greater than or equal to 0",
},
] as const)("$description", ({ input, expectedError }) => {
if (expectedError) {
expect(ApeKeysSchema).toReject(input, expectedError);
} else {
expect(ApeKeysSchema).toValidate(input);
}
});
});
});
91 changes: 91 additions & 0 deletions packages/schemas/__tests__/challenges.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { it, expect, describe } from "vitest";
import { ChallengeSchema } from "../src/challenges";

describe("challenges schema", () => {
describe("ChallengeSchema", () => {
it.each([
{
description: "minimal valid challenge",
input: {
name: "test-challenge",
display: "Test Challenge",
type: "other",
parameters: [],
},
},
{
description: "full challenge with requirements",
input: {
name: "speed-run",
display: "Speed Run",
autoRole: true,
type: "customTime",
message: "Complete quickly",
parameters: [60, true, null, "easy", ["58008"]],
requirements: {
wpm: { min: 100 },
acc: { exact: 0.95 },
afk: { max: 5 },
time: { min: 60 },
funbox: { exact: ["58008"] },
raw: { exact: 120 },
con: { exact: 10 },
config: { punctuation: true },
},
},
},
{
description: "exact wpm challenge",
input: {
name: "exact-wpm",
display: "Exact WPM",
type: "accuracy",
parameters: [],
requirements: { wpm: { exact: 50 } },
},
},
{
description: "missing name",
input: { display: "Test", type: "other", parameters: [] },
expectedError: "Required",
},
{
description: "missing display",
input: { name: "test", type: "other", parameters: [] },
expectedError: "Required",
},
{
description: "missing type",
input: { name: "test", display: "Test", parameters: [] },
expectedError: "Required",
},
{
description: "invalid type enum",
input: {
name: "test",
display: "Test",
type: "invalid",
parameters: [],
},
expectedError: "Invalid enum value",
},
{
description: "unrecognized key",
input: {
name: "test",
display: "Test",
type: "other",
parameters: [],
extra: true,
},
expectedError: "Unrecognized key",
},
] as const)("$description", ({ input, expectedError }) => {
if (expectedError) {
expect(ChallengeSchema).toReject(input, expectedError);
} else {
expect(ChallengeSchema).toValidate(input);
}
});
});
});
83 changes: 0 additions & 83 deletions packages/schemas/__tests__/config.spec.ts

This file was deleted.

Loading
Loading