Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(wip): add resource service unit tests and refactor helpers #768

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
test: add test cases for getPageById
karrui committed Oct 11, 2024
commit 5cdec2ca504c202b4556633b41c5dbabcf014f2d
Original file line number Diff line number Diff line change
@@ -6,7 +6,11 @@ import {

import type { Resource } from "../../database"
import { db } from "../../database"
import { getFullPageById, getSiteResourceById } from "../resource.service"
import {
getFullPageById,
getPageById,
getSiteResourceById,
} from "../resource.service"

describe("resource.service", () => {
describe("getSiteResourceById", () => {
@@ -183,4 +187,102 @@ describe("resource.service", () => {
expect(result).toBeUndefined()
})
})

describe("getPageById", () => {
it("should return the 'Page' resource with the given `id`", async () => {
// Arrange
const { site, page } = await setupPageResource({
resourceType: "Page",
})

// Act
const result = await getPageById(db, {
siteId: site.id,
resourceId: Number(page.id),
})

// Assert
expect(result).toMatchObject(page)
})

it("should return the 'RootPage' resource with the given `id`", async () => {
// Arrange
const { site, page: rootPage } = await setupPageResource({
resourceType: "RootPage",
})

// Act
const result = await getPageById(db, {
siteId: site.id,
resourceId: Number(rootPage.id),
})

// Assert
expect(result).toMatchObject(rootPage)
})

it("should return the 'CollectionPage' resource with the given `id`", async () => {
// Arrange
const { site, page: collectionPage } = await setupPageResource({
resourceType: "CollectionPage",
})

// Act
const result = await getPageById(db, {
siteId: site.id,
resourceId: Number(collectionPage.id),
})

// Assert
expect(result).toMatchObject(collectionPage)
})

it("should return undefined if resource type is not a supported type", async () => {
// Arrange
const { site, page } = await setupPageResource({
resourceType: "Folder",
})

// Act
const result = await getPageById(db, {
siteId: site.id,
resourceId: Number(page.id),
})

// Assert
expect(result).toBeUndefined()
})

it("should return undefined if no resource with the given `id` exists", async () => {
// Arrange
const { site } = await setupPageResource({
resourceType: "Page",
})

// Act
const result = await getPageById(db, {
siteId: site.id,
resourceId: 99999,
})

// Assert
expect(result).toBeUndefined()
})

it("should return undefined if the resource with the given `id` does not belong to the given `siteId`", async () => {
// Arrange
const { page } = await setupPageResource({
resourceType: "Page",
})

// Act
const result = await getPageById(db, {
siteId: 99999,
resourceId: Number(page.id),
})

// Assert
expect(result).toBeUndefined()
})
})
})

Unchanged files with check annotations Beta

export interface HeaderProps {
permalink: string
sitemap: any

Check warning on line 3 in packages/components/src/interfaces/internal/Header.ts

GitHub Actions / lint

Unexpected any. Specify a different type
}
export interface SidePaneProps {
sitemap: any

Check warning on line 2 in packages/components/src/interfaces/internal/SidePane.ts

GitHub Actions / lint

Unexpected any. Specify a different type
currentPermalink: string
}
},
},
},
typography: ({ theme }: any) => ({

Check warning on line 31 in packages/components/src/presets/classic.ts

GitHub Actions / lint

Unexpected any. Specify a different type
isomer: {
css: {
"--tw-prose-body": theme("colors.prose"),

Check warning on line 34 in packages/components/src/presets/classic.ts

GitHub Actions / lint

Unsafe assignment of an `any` value

Check warning on line 34 in packages/components/src/presets/classic.ts

GitHub Actions / lint

Unsafe call of an `any` typed value
"--tw-prose-headings": theme("colors.headings"),

Check warning on line 35 in packages/components/src/presets/classic.ts

GitHub Actions / lint

Unsafe assignment of an `any` value

Check warning on line 35 in packages/components/src/presets/classic.ts

GitHub Actions / lint

Unsafe call of an `any` typed value
"--tw-prose-bullets": theme("colors.prose"),

Check warning on line 36 in packages/components/src/presets/classic.ts

GitHub Actions / lint

Unsafe assignment of an `any` value

Check warning on line 36 in packages/components/src/presets/classic.ts

GitHub Actions / lint

Unsafe call of an `any` typed value
"--tw-prose-links": theme("colors.site.secondary"),

Check warning on line 37 in packages/components/src/presets/classic.ts

GitHub Actions / lint

Unsafe assignment of an `any` value
},
},
}),