Skip to content

test: Add test for creating primary_key column #105

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 2 commits into from
May 6, 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
30 changes: 28 additions & 2 deletions test/integration/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ describe('/tables', async () => {
is_nullable: false,
comment: 'foo',
// Currently no way to test these:
// isPrimaryKey: true,
// isUnique: true,
// is_unique: true
})

const { data: columns } = await axios.get(`${URL}/columns`)
Expand All @@ -330,6 +329,33 @@ describe('/tables', async () => {
await axios.delete(`${URL}/columns/${newTable.id}.1`)
await axios.delete(`${URL}/tables/${newTable.id}`)
})
it('POST /columns for primary key', 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_primary_key: true,
})

// https://wiki.postgresql.org/wiki/Retrieve_primary_key_columns
const { data: primaryKeys } = await axios.post(
`${URL}/query`,
{ query: `
SELECT a.attname
FROM pg_index i
JOIN pg_attribute a ON a.attrelid = i.indrelid
AND a.attnum = ANY(i.indkey)
WHERE i.indrelid = '${newTable.name}'::regclass
AND i.indisprimary;
` }
)
assert.equal(primaryKeys.length, 1)
assert.equal(primaryKeys[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