-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
296 test coverage on all things record hooks (#301)
* 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
1 parent
f18a889
commit 66c61de
Showing
15 changed files
with
761 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
plugins/record-hook/src/tests/bulkRecordHook.messages.e2e.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
55
plugins/record-hook/src/tests/bulkRecordHook.metadata.e2e.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) | ||
}) | ||
}) | ||
}) |
80 changes: 80 additions & 0 deletions
80
plugins/record-hook/src/tests/bulkRecordHook.objectData.e2e.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.