Skip to content

Commit

Permalink
fix(test): dedupe code
Browse files Browse the repository at this point in the history
  • Loading branch information
cgilbe27 committed Oct 19, 2023
1 parent 84dc6e0 commit 96501eb
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions packages/indexer-nibi/src/batchHandlers/queryBatchHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import { queryBatchHandler } from "./queryBatchHandler"
import { communityPoolQueryString } from "../query/communityPool"
import { delegationsQueryString } from "../query"

const checkFields = (objects: any[], fields: any[]) => {
objects.forEach((obj: any) => {
fields.forEach((field: string | any[]) => {
expect(obj).toHaveProperty(field)
})
})
}

describe("queryBatchHandler tests", () => {
test("queryBatchHandler", async () => {
const resp = await queryBatchHandler(
Expand All @@ -20,20 +28,16 @@ describe("queryBatchHandler tests", () => {
expect(resp).toHaveProperty("communityPool")
expect(resp).toHaveProperty("delegations")

if ((resp.communityPool?.length ?? 0) > 0) {
const [communityPool] = resp.communityPool ?? []
const fields = ["amount", "denom"]
fields.forEach((field: string) => {
expect(communityPool).toHaveProperty(field)
})
if (resp.communityPool?.length) {
const [communityPool] = resp.communityPool
const communityPoolFields = ["amount", "denom"]
checkFields([communityPool], communityPoolFields)
}

if ((resp.delegations?.length ?? 0) > 0) {
const [delegation] = resp.delegations ?? []
const fields = ["amount", "delegator", "validator"]
fields.forEach((field: string) => {
expect(delegation).toHaveProperty(field)
})
if (resp.delegations?.length) {
const [delegation] = resp.delegations
const delegationFields = ["amount", "delegator", "validator"]
checkFields([delegation], delegationFields)
}
})
})

0 comments on commit 96501eb

Please sign in to comment.