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
Next Next commit
test(resource.service): add test cases for getSiteResourceById
karrui committed Oct 11, 2024
commit d3d584dbdeddfa525e5077f32cf76ec916d045e7
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { setupPageResource } from "tests/integration/helpers/seed"

import type { Resource } from "../../database"
import { getSiteResourceById } from "../resource.service"

describe("resource.service", () => {
describe("getSiteResourceById", () => {
let actualPage: Resource
let actualSiteId: number

beforeAll(async () => {
const { site, page: _pageToId } = await setupPageResource({
resourceType: "Page",
})
actualPage = _pageToId
actualSiteId = site.id
const { page: _anotherPage, site: anotherSite } = await setupPageResource(
{
resourceType: "Page",
},
)

expect(anotherSite.id).not.toEqual(site.id)
})

it("should return the resource with the given `id`", async () => {
// Act
const result = await getSiteResourceById({
siteId: actualSiteId,
resourceId: actualPage.id,
})

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

it("should return the resource with the given `id` and `type`", async () => {
// Act
const result = await getSiteResourceById({
siteId: actualSiteId,
resourceId: actualPage.id,
type: "Page",
})

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

it("should return undefined if no resource with the given id exists", async () => {
// Act
const result = await getSiteResourceById({
siteId: actualSiteId,
resourceId: "999999",
})

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

it("should return undefined if the resource with the given `id` does not match given `type`", async () => {
// Arrange
expect(actualPage.type).not.toEqual("Folder")

// Act
const result = await getSiteResourceById({
siteId: actualSiteId,
resourceId: actualPage.id,
type: "Folder",
})

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

it("should return undefined if the resource with the given `id` does not belong to the given `siteId`", async () => {
// Arrange
expect(actualPage.siteId).not.toEqual(99999)

// Act
const result = await getSiteResourceById({
siteId: 99999,
resourceId: actualPage.id,
})

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