-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Update zapier trigger payload #8464
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,18 +24,18 @@ describe('triggers.trigger_record.created', () => { | |
requestDb( | ||
z, | ||
bundle, | ||
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operation}}}}`, | ||
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operations}}}}`, | ||
), | ||
bundle, | ||
); | ||
expect(checkDbResult.data.webhooks.edges[0].node.operation).toEqual( | ||
'create.company', | ||
expect(checkDbResult.data.webhooks.edges[0].node.operations[0]).toEqual( | ||
'company.created', | ||
); | ||
}); | ||
test('should succeed to unsubscribe', async () => { | ||
const bundle = getBundle({}); | ||
bundle.inputData.nameSingular = 'company'; | ||
bundle.inputData.operation = 'create'; | ||
bundle.inputData.operation = DatabaseEventAction.CREATED; | ||
bundle.targetUrl = 'https://test.com'; | ||
const result = await appTester( | ||
App.triggers[triggerRecordKey].operation.performSubscribe, | ||
|
@@ -54,7 +54,7 @@ describe('triggers.trigger_record.created', () => { | |
requestDb( | ||
z, | ||
bundle, | ||
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operation}}}}`, | ||
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operations}}}}`, | ||
), | ||
bundle, | ||
); | ||
|
@@ -83,27 +83,27 @@ describe('triggers.trigger_record.created', () => { | |
); | ||
expect(results.length).toEqual(1); | ||
const company = results[0]; | ||
expect(company.id).toEqual('d6ccb1d1-a90b-4822-a992-a0dd946592c9'); | ||
expect(company.record.id).toEqual('d6ccb1d1-a90b-4822-a992-a0dd946592c9'); | ||
}); | ||
it('should load companies from list', async () => { | ||
const bundle = getBundle({}); | ||
bundle.inputData.nameSingular = 'company'; | ||
bundle.inputData.operation = 'create'; | ||
bundle.inputData.operation = DatabaseEventAction.CREATED; | ||
const results = await appTester( | ||
App.triggers[triggerRecordKey].operation.performList, | ||
bundle, | ||
); | ||
expect(results.length).toBeGreaterThan(1); | ||
const firstCompany = results[0]; | ||
expect(firstCompany).toBeDefined(); | ||
expect(firstCompany.record).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('triggers.trigger_record.update', () => { | ||
test('should succeed to subscribe', async () => { | ||
const bundle = getBundle({}); | ||
bundle.inputData.nameSingular = 'company'; | ||
bundle.inputData.operation = 'update'; | ||
bundle.inputData.operation = DatabaseEventAction.UPDATED; | ||
bundle.targetUrl = 'https://test.com'; | ||
const result = await appTester( | ||
App.triggers[triggerRecordKey].operation.performSubscribe, | ||
|
@@ -116,18 +116,18 @@ describe('triggers.trigger_record.update', () => { | |
requestDb( | ||
z, | ||
bundle, | ||
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operation}}}}`, | ||
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operations}}}}`, | ||
), | ||
bundle, | ||
); | ||
expect(checkDbResult.data.webhooks.edges[0].node.operation).toEqual( | ||
'update.company', | ||
expect(checkDbResult.data.webhooks.edges[0].node.operations[0]).toEqual( | ||
'company.updated', | ||
); | ||
}); | ||
test('should succeed to unsubscribe', async () => { | ||
const bundle = getBundle({}); | ||
bundle.inputData.nameSingular = 'company'; | ||
bundle.inputData.operation = 'update'; | ||
bundle.inputData.operation = DatabaseEventAction.UPDATED; | ||
bundle.targetUrl = 'https://test.com'; | ||
const result = await appTester( | ||
App.triggers[triggerRecordKey].operation.performSubscribe, | ||
|
@@ -146,7 +146,7 @@ describe('triggers.trigger_record.update', () => { | |
requestDb( | ||
z, | ||
bundle, | ||
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operation}}}}`, | ||
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operations}}}}`, | ||
), | ||
bundle, | ||
); | ||
|
@@ -155,22 +155,23 @@ describe('triggers.trigger_record.update', () => { | |
it('should load companies from list', async () => { | ||
const bundle = getBundle({}); | ||
bundle.inputData.nameSingular = 'company'; | ||
bundle.inputData.operation = 'update'; | ||
bundle.inputData.operation = DatabaseEventAction.UPDATED; | ||
const results = await appTester( | ||
App.triggers[triggerRecordKey].operation.performList, | ||
bundle, | ||
); | ||
expect(results.length).toBeGreaterThan(1); | ||
const firstCompany = results[0]; | ||
expect(firstCompany).toBeDefined(); | ||
expect(firstCompany.record).toBeDefined(); | ||
expect(firstCompany.updatedFields).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('triggers.trigger_record.delete', () => { | ||
test('should succeed to subscribe', async () => { | ||
const bundle = getBundle({}); | ||
bundle.inputData.nameSingular = 'company'; | ||
bundle.inputData.operation = 'delete'; | ||
bundle.inputData.operation = DatabaseEventAction.DELETED; | ||
bundle.targetUrl = 'https://test.com'; | ||
const result = await appTester( | ||
App.triggers[triggerRecordKey].operation.performSubscribe, | ||
|
@@ -183,18 +184,18 @@ describe('triggers.trigger_record.delete', () => { | |
requestDb( | ||
z, | ||
bundle, | ||
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operation}}}}`, | ||
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operations}}}}`, | ||
), | ||
bundle, | ||
); | ||
expect(checkDbResult.data.webhooks.edges[0].node.operation).toEqual( | ||
'delete.company', | ||
expect(checkDbResult.data.webhooks.edges[0].node.operations[0]).toEqual( | ||
'company.deleted', | ||
); | ||
}); | ||
test('should succeed to unsubscribe', async () => { | ||
const bundle = getBundle({}); | ||
bundle.inputData.nameSingular = 'company'; | ||
bundle.inputData.operation = 'delete'; | ||
bundle.inputData.operation = DatabaseEventAction.DELETED; | ||
bundle.targetUrl = 'https://test.com'; | ||
const result = await appTester( | ||
App.triggers[triggerRecordKey].operation.performSubscribe, | ||
|
@@ -213,7 +214,7 @@ describe('triggers.trigger_record.delete', () => { | |
requestDb( | ||
z, | ||
bundle, | ||
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operation}}}}`, | ||
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operations}}}}`, | ||
), | ||
bundle, | ||
); | ||
|
@@ -222,15 +223,15 @@ describe('triggers.trigger_record.delete', () => { | |
it('should load companies from list', async () => { | ||
const bundle = getBundle({}); | ||
bundle.inputData.nameSingular = 'company'; | ||
bundle.inputData.operation = 'delete'; | ||
bundle.inputData.operation = DatabaseEventAction.DELETED; | ||
const results = await appTester( | ||
App.triggers[triggerRecordKey].operation.performList, | ||
bundle, | ||
); | ||
expect(results.length).toBeGreaterThan(1); | ||
const firstCompany = results[0]; | ||
expect(firstCompany).toBeDefined(); | ||
expect(firstCompany.id).toBeDefined(); | ||
expect(firstCompany.record.id).toBeDefined(); | ||
expect(Object.keys(firstCompany).length).toEqual(1); | ||
Comment on lines
233
to
235
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Inconsistent object structure check - other tests check firstCompany.record but this one checks firstCompany directly before checking firstCompany.record.id |
||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
export type InputData = { [x: string]: any }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider using a more specific type than |
||
|
||
export type ObjectData = { id: string } | { [x: string]: any }; | ||
|
||
export type NodeField = { | ||
type: FieldMetadataType; | ||
name: string; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import { Bundle, ZObject } from 'zapier-platform-core'; | ||
|
||
import { ObjectData } from '../../utils/data.types'; | ||
import handleQueryParams from '../../utils/handleQueryParams'; | ||
import requestDb, { | ||
requestDbViaRestApi, | ||
|
@@ -11,7 +10,6 @@ export enum DatabaseEventAction { | |
CREATED = 'created', | ||
UPDATED = 'updated', | ||
DELETED = 'deleted', | ||
DESTROYED = 'destroyed', | ||
} | ||
|
||
export const performSubscribe = async (z: ZObject, bundle: Bundle) => { | ||
|
@@ -81,7 +79,7 @@ const getNamePluralFromNameSingular = async ( | |
export const performList = async ( | ||
z: ZObject, | ||
bundle: Bundle, | ||
): Promise<ObjectData[]> => { | ||
): Promise<{ record: Record<string, any>; updatedFields?: string[] }[]> => { | ||
const nameSingular = bundle.inputData.nameSingular; | ||
const namePlural = await getNamePluralFromNameSingular( | ||
z, | ||
|
@@ -92,9 +90,9 @@ export const performList = async ( | |
return results.map((result) => ({ | ||
record: result, | ||
...(bundle.inputData.operation === DatabaseEventAction.UPDATED && { | ||
updatedFields: Object.keys(result).filter((key) => key !== 'id')?.[0] || [ | ||
'updatedField', | ||
], | ||
updatedFields: [ | ||
Object.keys(result).filter((key) => key !== 'id')?.[0], | ||
] || ['updatedField'], | ||
Comment on lines
+93
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: This logic will only ever return the first non-id field as the updated field, which may not be accurate if multiple fields were actually updated |
||
}), | ||
})); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Test only checks that updatedFields exists but not its content or structure. Consider adding more specific assertions