Skip to content

Commit

Permalink
Merge pull request #491 from bandada-infra/test/api-sdk
Browse files Browse the repository at this point in the history
Add tests to the API SDK
  • Loading branch information
vplasencia authored Apr 22, 2024
2 parents 3fd84eb + 577c99a commit 391667e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
1 change: 0 additions & 1 deletion .github/workflows/coverall.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: run-${{ matrix.tests }}
path-to-lcov: ./coverage/${{ matrix.tests }}/lcov.info
parallel: true

finish:
Expand Down
36 changes: 36 additions & 0 deletions libs/api-sdk/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Invite,
SupportedUrl
} from "./types"
import checkParameter from "./checkParameter"

jest.mock("@bandada/utils", () => {
const originalModule = jest.requireActual("@bandada/utils")
Expand Down Expand Up @@ -69,6 +70,13 @@ describe("Bandada API SDK", () => {
}
expect(fun).toThrow("The url and baseURL should be the same")
})
it("Should throw an error when the url has the wrong type", () => {
const url = 123
const fun = () => {
apiSdk = new ApiSdk(url as any)
}
expect(fun).toThrow("Parameter 'url' is not a string")
})
it("Should add the baseURL to config", () => {
const config = {
headers: {
Expand Down Expand Up @@ -600,4 +608,32 @@ describe("Bandada API SDK", () => {
})
})
})
describe("Check Parameter", () => {
describe("Should not throw an error if the parameter has the expected type", () => {
it("Should not throw an error if the parameter is a string and the function expects a string", () => {
const url = "http://localhost:3000"
const fun = () => {
checkParameter(url, "url", "string")
}
expect(fun).not.toThrow()
})
})

describe("Should throw an error if the parameter does not have the expected type", () => {
it("Should throw an error if the parameter is a number and the function expects a string", () => {
const url = 123
const fun = () => {
checkParameter(url, "url", "string")
}
expect(fun).toThrow("Parameter 'url' is not a string")
})
it("Should throw an error if the parameter is a string and the function expects an object", () => {
const url = "http://localhost:3000"
const fun = () => {
checkParameter(url, "url", "object")
}
expect(fun).toThrow("Parameter 'url' is not an object")
})
})
})
})

0 comments on commit 391667e

Please sign in to comment.