Skip to content

Commit

Permalink
fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
csikb committed Apr 5, 2024
1 parent b45a78b commit 1769b47
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/database/postgres.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Pool } from 'pg'
import pg from 'pg'
import config from '../config.js'

export default new Pool(config.database)
export default new pg.Pool(config.database)
3 changes: 2 additions & 1 deletion src/middleware/postgraphile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import config from '../config.js'
import { postgraphile, PostGraphileOptions } from 'postgraphile'
import PgSimplifyInflectorPlugin from '@graphile-contrib/pg-simplify-inflector'
import { postgres } from '../database/index.js'

const options: PostGraphileOptions = {
Expand All @@ -11,7 +12,7 @@ const options: PostGraphileOptions = {
setofFunctionsContainNulls: false,
ignoreRBAC: false,
extendedErrors: ['errcode'],
appendPlugins: [require('@graphile-contrib/pg-simplify-inflector')],
appendPlugins: [PgSimplifyInflectorPlugin.default],
graphiql: false,
enableQueryBatching: true,
disableQueryLog: true,
Expand Down
12 changes: 7 additions & 5 deletions tests/database/postgres.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { describe, it, vi, expect } from 'vitest'
import { Pool } from 'pg'
import pg from 'pg'
import config from '../../src/config.js'

vi.mock('pg', () => {
return {
Pool: vi.fn(),
default: {
Pool: vi.fn(),
},
}
})
vi.mock('../../src/config', () => ({
Expand All @@ -13,7 +15,7 @@ vi.mock('../../src/config', () => ({
},
}))

const mockPool = vi.mocked(Pool)
const mockPg = vi.mocked(pg)
const mockConfig = vi.mocked(config)

describe('postgres', () => {
Expand All @@ -22,7 +24,7 @@ describe('postgres', () => {

const { default: actual } = await import('../../src/database/postgres.js')

expect.soft(actual).toStrictEqual(new mockPool(mockConfig.database))
expect.soft(mockPool).toHaveBeenCalledWith(mockConfig.database)
expect.soft(actual).toStrictEqual(new pg.Pool(mockConfig.database))
expect.soft(pg.Pool).toHaveBeenCalledWith(mockConfig.database)
})
})

0 comments on commit 1769b47

Please sign in to comment.