Skip to content

Commit 2e9b4cd

Browse files
authored
Merge pull request #108 from wasabigeek/test/unique-constraint
test: Add test for is_unique columns
2 parents b1787b6 + ec145ed commit 2e9b4cd

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

test/integration/index.spec.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,7 @@ describe('/tables', async () => {
312312
type: 'int2',
313313
default_value: 42,
314314
is_nullable: false,
315-
comment: 'foo',
316-
// Currently no way to test these:
317-
// is_unique: true
315+
comment: 'foo'
318316
})
319317

320318
const { data: columns } = await axios.get(`${URL}/columns`)
@@ -356,6 +354,33 @@ describe('/tables', async () => {
356354
await axios.delete(`${URL}/columns/${newTable.id}.1`)
357355
await axios.delete(`${URL}/tables/${newTable.id}`)
358356
})
357+
it('POST /columns with unique constraint', async () => {
358+
const { data: newTable } = await axios.post(`${URL}/tables`, { name: 'foo' })
359+
await axios.post(`${URL}/columns`, {
360+
table_id: newTable.id,
361+
name: 'bar',
362+
type: 'int2',
363+
is_unique: true,
364+
})
365+
366+
const { data: uniqueColumns } = await axios.post(
367+
`${URL}/query`,
368+
{ query: `
369+
SELECT a.attname
370+
FROM pg_index i
371+
JOIN pg_constraint c ON c.conindid = i.indexrelid
372+
JOIN pg_attribute a ON a.attrelid = i.indrelid
373+
AND a.attnum = ANY(i.indkey)
374+
WHERE i.indrelid = '${newTable.name}'::regclass
375+
AND i.indisunique;
376+
` }
377+
)
378+
assert.equal(uniqueColumns.length, 1)
379+
assert.equal(uniqueColumns[0].attname, 'bar')
380+
381+
await axios.delete(`${URL}/columns/${newTable.id}.1`)
382+
await axios.delete(`${URL}/tables/${newTable.id}`)
383+
})
359384
it('POST /columns array type', async () => {
360385
const { data: newTable } = await axios.post(`${URL}/tables`, { name: 'a' })
361386
await axios.post(`${URL}/columns`, {

0 commit comments

Comments
 (0)