Skip to content

[TILES-V2-11]: add unit and integration tests for tiles v2 #1033

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

Open
wants to merge 6 commits into
base: tiles-v2/load-tests
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,87 +10,93 @@ import {
generateMockTableRowData,
} from '@/graphql/__tests__/mutations/tiles/table.mock'
import TableMetadata from '@/models/table-metadata'
import { DatabaseType } from '@/models/tiles/types'
import User from '@/models/user'
import Context from '@/types/express/context'

import tiles from '../..'
import createRowAction from '../../actions/create-row'

describe('tiles create row action', () => {
let context: Context
let dummyTable: TableMetadata
let dummyColumnIds: string[]
let editor: User
let viewer: User
let $: IGlobalVariable
describe.each([['ddb'], ['pg']])(
'tiles create row action: %s',
(databaseType: DatabaseType) => {
let context: Context
let dummyTable: TableMetadata
let dummyColumnIds: string[]
let editor: User
let viewer: User
let $: IGlobalVariable

beforeEach(async () => {
context = await generateMockContext()
beforeEach(async () => {
context = await generateMockContext()

const mockTable = await generateMockTable({
userId: context.currentUser.id,
})
dummyTable = mockTable.table
editor = mockTable.editor
viewer = mockTable.viewer
const mockTable = await generateMockTable({
userId: context.currentUser.id,
databaseType,
})
dummyTable = mockTable.table
editor = mockTable.editor
viewer = mockTable.viewer

dummyColumnIds = await generateMockTableColumns({
tableId: dummyTable.id,
numColumns: 5,
})
dummyColumnIds = await generateMockTableColumns({
tableId: dummyTable.id,
numColumns: 5,
databaseType,
})

const validData = generateMockTableRowData({ columnIds: dummyColumnIds })
const rowData = Object.keys(validData).map((columnId) => ({
columnId,
cellValue: validData[columnId],
}))
const validData = generateMockTableRowData({ columnIds: dummyColumnIds })
const rowData = Object.keys(validData).map((columnId) => ({
columnId,
cellValue: validData[columnId],
}))

$ = {
user: context.currentUser,
flow: {
id: '123',
userId: context.currentUser.id,
},
step: {
id: '456',
appKey: tiles.name,
key: createRowAction.key,
position: 2,
parameters: {
tableId: dummyTable.id,
rowData,
$ = {
user: context.currentUser,
flow: {
id: '123',
userId: context.currentUser.id,
},
step: {
id: '456',
appKey: tiles.name,
key: createRowAction.key,
position: 2,
parameters: {
tableId: dummyTable.id,
rowData,
},
},
},
app: {
name: tiles.name,
},
setActionItem: vi.fn(),
} as unknown as IGlobalVariable
})
app: {
name: tiles.name,
},
setActionItem: vi.fn(),
} as unknown as IGlobalVariable
})

it('should allow owners to create row', async () => {
await expect(createRowAction.run($)).resolves.toBeUndefined()
expect($.setActionItem).toBeCalled()
})
it('should allow owners to create row', async () => {
await expect(createRowAction.run($)).resolves.toBeUndefined()
expect($.setActionItem).toBeCalled()
})

it('should allow editors to create row', async () => {
$.user = editor
await expect(createRowAction.run($)).resolves.toBeUndefined()
expect($.setActionItem).toBeCalled()
})
it('should allow editors to create row', async () => {
$.user = editor
await expect(createRowAction.run($)).resolves.toBeUndefined()
expect($.setActionItem).toBeCalled()
})

it('should not allow viewers to create row', async () => {
$.user = viewer
await expect(createRowAction.run($)).rejects.toThrow(StepError)
})
it('should not allow viewers to create row', async () => {
$.user = viewer
await expect(createRowAction.run($)).rejects.toThrow(StepError)
})

it('should throw correct error if Tile deleted', async () => {
$.user = editor
await TableMetadata.query()
.patch({
deletedAt: new Date().toISOString(),
})
.where({ id: $.step.parameters.tableId })
await expect(createRowAction.run($)).rejects.toThrow(StepError)
})
})
it('should throw correct error if Tile deleted', async () => {
$.user = editor
await TableMetadata.query()
.patch({
deletedAt: new Date().toISOString(),
})
.where({ id: $.step.parameters.tableId })
await expect(createRowAction.run($)).rejects.toThrow(StepError)
})
},
)
Loading