Skip to content

Commit 4eebc65

Browse files
committed
test(tables, views, foreign-tables): make columns optional
1 parent e1cfc6e commit 4eebc65

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

test/lib/foreign-tables.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,20 @@ test('list', async () => {
7676
`
7777
)
7878
})
79+
80+
test('list without columns', async () => {
81+
const res = await pgMeta.foreignTables.list({ includeColumns: false })
82+
expect(res.data?.find(({ name }) => name === 'foreign_table')).toMatchInlineSnapshot(
83+
{
84+
id: expect.any(Number),
85+
},
86+
`
87+
{
88+
"comment": null,
89+
"id": Any<Number>,
90+
"name": "foreign_table",
91+
"schema": "public",
92+
}
93+
`
94+
)
95+
})

test/lib/tables.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,61 @@ test('list', async () => {
129129
)
130130
})
131131

132+
test('list without columns', async () => {
133+
const res = await pgMeta.tables.list({ includeColumns: false })
134+
135+
const { columns, primary_keys, relationships, ...rest }: any = res.data?.find(
136+
({ name }) => name === 'users'
137+
)
138+
139+
expect({
140+
primary_keys: primary_keys.map(({ table_id, ...rest }: any) => rest),
141+
relationships: relationships.map(({ id, ...rest }: any) => rest),
142+
...rest,
143+
}).toMatchInlineSnapshot(
144+
{
145+
bytes: expect.any(Number),
146+
dead_rows_estimate: expect.any(Number),
147+
id: expect.any(Number),
148+
live_rows_estimate: expect.any(Number),
149+
size: expect.any(String),
150+
},
151+
`
152+
{
153+
"bytes": Any<Number>,
154+
"comment": null,
155+
"dead_rows_estimate": Any<Number>,
156+
"id": Any<Number>,
157+
"live_rows_estimate": Any<Number>,
158+
"name": "users",
159+
"primary_keys": [
160+
{
161+
"name": "id",
162+
"schema": "public",
163+
"table_name": "users",
164+
},
165+
],
166+
"relationships": [
167+
{
168+
"constraint_name": "todos_user-id_fkey",
169+
"source_column_name": "user-id",
170+
"source_schema": "public",
171+
"source_table_name": "todos",
172+
"target_column_name": "id",
173+
"target_table_name": "users",
174+
"target_table_schema": "public",
175+
},
176+
],
177+
"replica_identity": "DEFAULT",
178+
"rls_enabled": false,
179+
"rls_forced": false,
180+
"schema": "public",
181+
"size": Any<String>,
182+
}
183+
`
184+
)
185+
})
186+
132187
test('list tables with included schemas', async () => {
133188
let res = await pgMeta.tables.list({
134189
includedSchemas: ['public'],

test/lib/views.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,21 @@ test('list', async () => {
7474
`
7575
)
7676
})
77+
78+
test('list without columns', async () => {
79+
const res = await pgMeta.views.list({ includeColumns: false })
80+
expect(res.data?.find(({ name }) => name === 'todos_view')).toMatchInlineSnapshot(
81+
{
82+
id: expect.any(Number),
83+
},
84+
`
85+
{
86+
"comment": null,
87+
"id": Any<Number>,
88+
"is_updatable": true,
89+
"name": "todos_view",
90+
"schema": "public",
91+
}
92+
`
93+
)
94+
})

0 commit comments

Comments
 (0)