Skip to content

Commit

Permalink
Create reverseProxyCheckerLogic.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
zlwaterfield committed Mar 20, 2024
1 parent 9abfda6 commit 49d0deb
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { expectLogic } from 'kea-test-utils'

import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'

import { reverseProxyCheckerLogic } from './reverseProxyCheckerLogic'

const hasReverseProxyValues = [['https://proxy.example.com'], [null]]
const doesNotHaveReverseProxyValues = [[null], [null]]

const useMockedValues = (results: { timestamp: string; $lib_custom_api_host?: string }[]): void => {
useMocks({
post: {
'/api/projects/:team/query': () => [
200,
{
results,
},
],
},
})
}

describe('reverseProxyCheckerLogic', () => {
let logic: ReturnType<typeof reverseProxyCheckerLogic.build>

beforeEach(() => {
initKeaTests()
localStorage.clear()
logic = reverseProxyCheckerLogic()
})

afterEach(() => {
logic.unmount()
})

it('should not have a reverse proxy set - when no data', async () => {
useMockedValues([])

logic.mount()
await expectLogic(logic).toFinishAllListeners().toMatchValues({
hasReverseProxy: false,
})
})

it('should not have a reverse proxy set - when data with no lib_custom_api_host values', async () => {
useMockedValues(doesNotHaveReverseProxyValues)

Check failure on line 47 in frontend/src/lib/components/ReverseProxyChecker/reverseProxyCheckerLogic.test.ts

View workflow job for this annotation

GitHub Actions / Code quality checks

Argument of type 'null[][]' is not assignable to parameter of type '{ timestamp: string; $lib_custom_api_host?: string | undefined; }[]'.

logic.mount()
await expectLogic(logic).toFinishAllListeners().toMatchValues({
hasReverseProxy: false,
})
})

it('should have a reverse proxy set', async () => {
useMockedValues(hasReverseProxyValues)

Check failure on line 56 in frontend/src/lib/components/ReverseProxyChecker/reverseProxyCheckerLogic.test.ts

View workflow job for this annotation

GitHub Actions / Code quality checks

Argument of type '(string[] | null[])[]' is not assignable to parameter of type '{ timestamp: string; $lib_custom_api_host?: string | undefined; }[]'.

logic.mount()
await expectLogic(logic).toFinishAllListeners().toMatchValues({
hasReverseProxy: true,
})
})
})

0 comments on commit 49d0deb

Please sign in to comment.