Skip to content

test: Add test for is_unique columns #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions test/integration/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,7 @@ describe('/tables', async () => {
type: 'int2',
default_value: 42,
is_nullable: false,
comment: 'foo',
// Currently no way to test these:
// is_unique: true
comment: 'foo'
})

const { data: columns } = await axios.get(`${URL}/columns`)
Expand Down Expand Up @@ -356,6 +354,33 @@ describe('/tables', async () => {
await axios.delete(`${URL}/columns/${newTable.id}.1`)
await axios.delete(`${URL}/tables/${newTable.id}`)
})
it('POST /columns with unique constraint', async () => {
const { data: newTable } = await axios.post(`${URL}/tables`, { name: 'foo' })
await axios.post(`${URL}/columns`, {
table_id: newTable.id,
name: 'bar',
type: 'int2',
is_unique: true,
})

const { data: uniqueColumns } = await axios.post(
`${URL}/query`,
{ query: `
SELECT a.attname
FROM pg_index i
JOIN pg_constraint c ON c.conindid = i.indexrelid
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically speaking looking at the index alone should be enough (PG uses a unique index to enforce a unique constraint) but I added this for completeness, since we specifically want to create a constraint.

JOIN pg_attribute a ON a.attrelid = i.indrelid
AND a.attnum = ANY(i.indkey)
WHERE i.indrelid = '${newTable.name}'::regclass
AND i.indisunique;
` }
)
assert.equal(uniqueColumns.length, 1)
assert.equal(uniqueColumns[0].attname, 'bar')

await axios.delete(`${URL}/columns/${newTable.id}.1`)
await axios.delete(`${URL}/tables/${newTable.id}`)
})
it('POST /columns array type', async () => {
const { data: newTable } = await axios.post(`${URL}/tables`, { name: 'a' })
await axios.post(`${URL}/columns`, {
Expand Down