Skip to content

Commit

Permalink
296 test coverage on all things record hooks (#301)
Browse files Browse the repository at this point in the history
* create simple data tests

* add files for object data tests

* fix typos

* make tests pass until fully implemented

* add enum test

* remove console dirs

* run prettier

* change array index to better selector

* addError tests

* run prettier

* metadata and message tests

* Update plugins/record-hook/src/tests/recordHook.messages.e2e.spec.ts

Co-authored-by: Carl Brugger <[email protected]>

* remove debug code

---------

Co-authored-by: Carl Brugger <[email protected]>
  • Loading branch information
madaley1 and carlbrugger authored Nov 27, 2023
1 parent f18a889 commit 66c61de
Show file tree
Hide file tree
Showing 15 changed files with 761 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .env.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ FLATFILE_ENVIRONMENT_ID=us_env_aeCyg5u9
FLATFILE_BEARER_TOKEN="${FLATFILE_API_KEY}"
AGENT_INTERNAL_URL="https://platform.flatfile.com/api"

WEBHOOK_SITE_URL="https://webhook.site/077ab8ee-8570-48b0-82d7-f7561ae75dc2"
WEBHOOK_SITE_URL="https://webhook.site/dea90400-e014-479b-9258-410d0998b0cf"
4 changes: 2 additions & 2 deletions plugins/record-hook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"build": "parcel build",
"dev": "parcel watch",
"check": "tsc ./**/*.ts --noEmit --esModuleInterop",
"test": "jest ./**/*.spec.ts --config=../../jest.config.js --runInBand"
"test": "jest ./src/tests/*.spec.ts --config=../../jest.config.js --runInBand"
},
"keywords": [],
"author": "Alex Hollenbeck",
Expand All @@ -41,4 +41,4 @@
"devDependencies": {
"axios": "^1.4.0"
}
}
}
2 changes: 1 addition & 1 deletion plugins/record-hook/src/RecordHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export const BulkRecordHook = async (
}
})
} catch (e) {
console.log(`Error getting records: ${e}`)
console.error(`An error occurred while running the handler: ${e.message}`)
}

return handler
Expand Down
97 changes: 0 additions & 97 deletions plugins/record-hook/src/record.hook.e2e.spec.ts

This file was deleted.

60 changes: 60 additions & 0 deletions plugins/record-hook/src/tests/bulkRecordHook.messages.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {
createRecords,
deleteSpace,
getRecords,
setupListener,
setupSimpleWorkbook,
setupSpace,
} from '@flatfile/utils-testing'

import { bulkRecordHook } from '..'

import {
defaultSimpleValueData,
defaultSimpleValueSchema,
} from './simpleTestData'

const messageValue = 'this is a name'

describe('bulkRecordHook() simple data modification e2e', () => {
const listener = setupListener()

let spaceId
let sheetId

beforeAll(async () => {
const space = await setupSpace()
spaceId = space.id
const workbook = await setupSimpleWorkbook(
space.id,
defaultSimpleValueSchema
)
sheetId = workbook.sheets[0].id
})

afterAll(async () => {
await deleteSpace(spaceId)
})

describe('Assigns messages without assigning a new value', () => {
it('correctly assigns messages', async () => {
listener.use(
bulkRecordHook('test', (records) =>
records.map((record) => {
record.addInfo('name', messageValue)
})
)
)
await createRecords(sheetId, defaultSimpleValueData)

await listener.waitFor('commit:created')
const records = await getRecords(sheetId)
expect(
records[records.length - 2].values['name'].messages[0]
).toMatchObject({ type: 'info', message: messageValue })
expect(
records[records.length - 1].values['name'].messages[0]
).toMatchObject({ type: 'info', message: messageValue })
})
})
})
55 changes: 55 additions & 0 deletions plugins/record-hook/src/tests/bulkRecordHook.metadata.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
createRecords,
deleteSpace,
getRecords,
setupListener,
setupSimpleWorkbook,
setupSpace,
} from '@flatfile/utils-testing'

import { bulkRecordHook } from '..'

import {
defaultSimpleValueData,
defaultSimpleValueSchema,
} from './simpleTestData'

describe('bulkRecordHook() simple data modification e2e', () => {
const listener = setupListener()

let spaceId
let sheetId

beforeAll(async () => {
const space = await setupSpace()
spaceId = space.id
const workbook = await setupSimpleWorkbook(
space.id,
defaultSimpleValueSchema
)
sheetId = workbook.sheets[0].id
})

afterAll(async () => {
await deleteSpace(spaceId)
})

describe('Assigns metadata without assigning a new value', () => {
it('correctly assigns metadata', async () => {
listener.use(
bulkRecordHook('test', (records) =>
records.map((record) => {
record.setMetadata({ test: true })
})
)
)
await createRecords(sheetId, defaultSimpleValueData)

await listener.waitFor('commit:created')
const records = await getRecords(sheetId)

expect(records[records.length - 2].metadata).toMatchObject({ test: true })
expect(records[records.length - 1].metadata).toMatchObject({ test: true })
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import {
createRecords,
deleteSpace,
getRecords,
setupListener,
setupSimpleWorkbook,
setupSpace,
} from '@flatfile/utils-testing'

import { bulkRecordHook } from '..'

import {
defaultObjectValueData,
defaultObjectValueSchema,
} from './objectTestData'

jest.setTimeout(10_000)

const enumValue = 'secondValue'
const badEnumValue = 'badValue'

describe('bulkRecordHook() object data modification e2e', () => {
const listener = setupListener()

let spaceId
let sheetId

beforeAll(async () => {
const space = await setupSpace()
spaceId = space.id
const workbook = await setupSimpleWorkbook(
space.id,
defaultObjectValueSchema
)
sheetId = workbook.sheets[0].id
})

afterAll(async () => {
await deleteSpace(spaceId)
})

describe('Assigns a valid value to an enum', () => {
beforeEach(async () => {
listener.use(
bulkRecordHook('test', (records) =>
records.map((record) => {
record.set('array', enumValue)
})
)
)
})

it('correctly modifies Object values', async () => {
await createRecords(sheetId, defaultObjectValueData)

await listener.waitFor('commit:created')
const records = await getRecords(sheetId)
expect(records[records.length - 1].valid).toBeTruthy()
})
})
describe('Assigns an invalid value to an enum', () => {
beforeEach(async () => {
listener.use(
bulkRecordHook('test', (records) =>
records.map((record) => {
record.set('array', badEnumValue)
})
)
)
})

it('correctly modifies Object values', async () => {
await createRecords(sheetId, defaultObjectValueData)

await listener.waitFor('commit:created')
const records = await getRecords(sheetId)
expect(records[records.length - 1].valid).toBeFalsy()
})
})
})
Loading

0 comments on commit 66c61de

Please sign in to comment.