Skip to content

Commit

Permalink
Get redirect test to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
ptgott committed Oct 10, 2024
1 parent 6eeca8e commit 5d02681
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
18 changes: 18 additions & 0 deletions server/config-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,24 @@ export const checkURLsForCorrespondingFiles = (
}, []);
};

// checkDuplicateRedirects checks the provided redirects for duplicates and
// returns an array of Redirect objects. Duplicate checks are based on the
// source of each redirect.
export const checkDuplicateRedirects = (
redirects: Array<Redirect>
): Array<Redirect> => {
const result: Array<Redirect> = [];
const uniques = new Set();
redirects.forEach((r) => {
if (uniques.has(r.source)) {
result.push(r);
return;
}
uniques.add(r.source);
});
return result;
};

// checkURLForCorrespondingFile determines whether a file exists in the content
// directory rooted at dirRoot for the file corresponding to the provided URL path.// If a file does not exist, it returns false.
const correspondingFileExistsForURL = (
Expand Down
56 changes: 55 additions & 1 deletion uvu-tests/config-docs.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { Redirect } from "next/dist/lib/load-custom-routes";

Check failure on line 1 in uvu-tests/config-docs.test.ts

View workflow job for this annotation

GitHub Actions / Lint code base

Duplicate identifier 'Redirect'.
import { suite } from "uvu";
import * as assert from "uvu/assert";
import { Config, checkURLsForCorrespondingFiles } from "../server/config-docs";
import {
Config,
checkURLsForCorrespondingFiles,
checkDuplicateRedirects,
} from "../server/config-docs";
import { generateNavPaths } from "../server/pages-helpers";
import { randomUUID } from "crypto";
import { join } from "path";
import { Volume, createFsFromVolume } from "memfs";
import type { Redirect } from "next/dist/lib/load-custom-routes";

Check failure on line 13 in uvu-tests/config-docs.test.ts

View workflow job for this annotation

GitHub Actions / Lint code base

Duplicate identifier 'Redirect'.

const Suite = suite("server/config-docs");

Expand Down Expand Up @@ -459,4 +464,53 @@ title: Deploying the Database Service on Kubernetes
);
});

Suite("Checks for duplicate redirects", () => {
const redirects: Array<Redirect> = [
{
source: "/getting-started/",
destination: "/get-started/",
permanent: true,
},
{
source: "/getting-started/",
destination: "/get-started/",
permanent: true,
},
{
source: "/application-access/",
destination: "/connecting-apps/",
permanent: true,
},
{
source: "/application-access/",
destination: "/connecting-apps/",
permanent: true,
},
{
source: "/database-access/",
destination: "/connecting-databases/",
permanent: true,
},
];

const expected: Array<Redirect> = [
{
source: "/getting-started/",
destination: "/get-started/",
permanent: true,
},
{
source: "/application-access/",
destination: "/connecting-apps/",
permanent: true,
},
];

const actual = checkDuplicateRedirects(redirects);
assert.equal(actual, expected);
});

// TODO: Test for from files that exist (maybe do this in
// CheckForCorresponding?)

Suite.run();

0 comments on commit 5d02681

Please sign in to comment.