Skip to content

Commit

Permalink
feat(indexer-nibi 99% coverage): coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
cgilbe27 committed Oct 19, 2023
1 parent 7c9ee03 commit b4f84fa
Show file tree
Hide file tree
Showing 33 changed files with 1,034 additions and 491 deletions.
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ module.exports = function (root = __dirname) {
"packages/nibijs/src/**/*.{js,jsx,ts,tsx}",
"!**/node_modules/**",
"!**/dist/**",
"!**/index.ts",
"!**/nibijs/src/test/helpers.ts",
],

// The directory where Jest should output its coverage files
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CodegenConfig } from "@graphql-codegen/cli"

const config: CodegenConfig = {
export default {
schema: {
"indexer-nibi": {
loader: "./src/graphql-codegen/codegen-loader.js",
Expand All @@ -26,6 +26,4 @@ const config: CodegenConfig = {
},
},
},
}

export default config
} as CodegenConfig
2 changes: 1 addition & 1 deletion packages/indexer-nibi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"scripts": {
"build": "tsc --build",
"build:watch": "tsc --build --watch",
"gql-generate": "rm -rf src/gql && graphql-code-generator --config ./src/graphql-codegen/codegen.ts",
"gql-generate": "rm -rf src/gql && graphql-code-generator --config codegen.ts",
"clean": "tsc --clean",
"test": "jest",
"test:watch": "jest --watch",
Expand Down
39 changes: 39 additions & 0 deletions packages/indexer-nibi/src/batchHandlers/queryBatchHandler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { queryBatchHandler } from "./queryBatchHandler"
import { communityPoolQueryString } from "../query/communityPool"
import { delegationsQueryString } from "../query"

describe("queryBatchHandler tests", () => {
test("queryBatchHandler", async () => {
const resp = await queryBatchHandler(
[
communityPoolQueryString({}, true),
delegationsQueryString(
{
limit: 1,
},
true
),
],
"https://hm-graphql.itn-3.nibiru.fi/query"
)

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.delegations?.length ?? 0) > 0) {
const [delegation] = resp.delegations ?? []
const fields = ["amount", "delegator", "validator"]
fields.forEach((field: string) => {
expect(delegation).toHaveProperty(field)
})
}
})
})
19 changes: 0 additions & 19 deletions packages/indexer-nibi/src/enum.ts

This file was deleted.

43 changes: 8 additions & 35 deletions packages/indexer-nibi/src/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,44 +66,17 @@ export const gqlQuery = <T>(
properties: string,
excludeParentObject?: boolean
) => {
let queryArgList = []

if (
typedQueryArgs.where !== undefined ||
typedQueryArgs.limit !== undefined ||
typedQueryArgs.order_by !== undefined ||
typedQueryArgs.order_desc !== undefined ||
typedQueryArgs.order !== undefined ||
typedQueryArgs.orderDesc !== undefined
) {
if (typedQueryArgs.where !== undefined) {
queryArgList.push(getWhereArgArr(typedQueryArgs.where))
}

if (typedQueryArgs.limit !== undefined) {
queryArgList.push(arg("limit", typedQueryArgs.limit))
}
const queryArgList = []

if (typedQueryArgs.order_by !== undefined) {
queryArgList.push(arg("order_by", typedQueryArgs.order_by, true))
}

if (typedQueryArgs.order !== undefined) {
queryArgList.push(arg("order", typedQueryArgs.order, true))
}
if (typedQueryArgs.where !== undefined) {
queryArgList.push(getWhereArgArr(typedQueryArgs.where))
}

if (typedQueryArgs.order_desc !== undefined) {
queryArgList.push(arg("order_desc", typedQueryArgs.order_desc))
}
delete typedQueryArgs.where

if (typedQueryArgs.orderDesc !== undefined) {
queryArgList.push(arg("orderDesc", typedQueryArgs.orderDesc))
}
} else {
queryArgList = Object.keys(typedQueryArgs).map((key) =>
arg(key, typedQueryArgs[key])
)
}
Object.keys(typedQueryArgs).map((key) =>
queryArgList.push(arg(key, typedQueryArgs[key], true))
)

const hasQueryList = (char: string) => (queryArgList.length > 0 ? char : "")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ module.exports = async () => {
return buildClientSchema(data)
} catch (error) {
console.error(error)
throw error
return undefined
}
}
10 changes: 10 additions & 0 deletions packages/indexer-nibi/src/graphql-codegen/codegen-loader.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { GraphQLSchema } from "graphql"

const loader = require("./codegen-loader")

describe("codegen-loader tests", () => {
test("codegen-loader", async () => {
const testResult = await loader()
expect(testResult).toBeInstanceOf(GraphQLSchema)
})
})
Loading

0 comments on commit b4f84fa

Please sign in to comment.