-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2cce3ed
commit 4c335d7
Showing
2 changed files
with
45 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ import { forSnapshot } from '~/tests/helpers/snapshots' | |
import { getFirstTeam, resetTestDatabase } from '~/tests/helpers/sql' | ||
|
||
import { createPlugin, createPluginConfig } from '../../../tests/helpers/sql' | ||
import { Hub, Team } from '../../types' | ||
import { Hub, PluginConfig, Team } from '../../types' | ||
import { closeHub, createHub } from '../../utils/db/hub' | ||
import { DESTINATION_PLUGINS_BY_ID, TRANSFORMATION_PLUGINS_BY_ID } from '../legacy-plugins' | ||
import { LegacyDestinationPlugin, LegacyTransformationPlugin } from '../legacy-plugins/types' | ||
|
@@ -29,6 +29,7 @@ describe('LegacyPluginExecutorService', () => { | |
let globals: HogFunctionInvocationGlobalsWithInputs | ||
let fn: HogFunctionType | ||
let mockFetch: jest.Mock | ||
let pluginConfig: PluginConfig | ||
|
||
const customerIoPlugin = DESTINATION_PLUGINS_BY_ID['plugin-customerio-plugin'] | ||
|
||
|
@@ -41,11 +42,29 @@ describe('LegacyPluginExecutorService', () => { | |
fn = createHogFunction({ | ||
name: 'Plugin test', | ||
template_id: customerIoPlugin.template.id, | ||
team_id: team.id, | ||
}) | ||
|
||
const fixedTime = DateTime.fromObject({ year: 2025, month: 1, day: 1 }, { zone: 'UTC' }) | ||
jest.spyOn(Date, 'now').mockReturnValue(fixedTime.toMillis()) | ||
|
||
const plugin = await createPlugin(hub.postgres, { | ||
organization_id: team.organization_id, | ||
name: 'first-time-event-tracker', | ||
plugin_type: 'source', | ||
is_global: false, | ||
source__index_ts: ` | ||
export async function runEveryMinute() { | ||
console.info(JSON.stringify(['runEveryMinute'])) | ||
} | ||
`, | ||
}) | ||
pluginConfig = await createPluginConfig(hub.postgres, { | ||
name: 'first-time-event-tracker', | ||
team_id: team.id, | ||
plugin_id: plugin.id, | ||
} as any) | ||
|
||
mockFetch = jest.fn(() => | ||
Promise.resolve({ | ||
status: 200, | ||
|
@@ -80,6 +99,7 @@ describe('LegacyPluginExecutorService', () => { | |
customerioSiteId: '1234567890', | ||
customerioToken: 'cio-token', | ||
email: '[email protected]', | ||
legacy_plugin_config_id: pluginConfig.id, | ||
}, | ||
} | ||
}) | ||
|
@@ -151,6 +171,9 @@ describe('LegacyPluginExecutorService', () => { | |
|
||
const res = await service.execute(invocation) | ||
|
||
expect(res.finished).toBe(true) | ||
expect(res.error).toBeUndefined() | ||
|
||
expect(customerIoPlugin.onEvent).toHaveBeenCalledTimes(1) | ||
expect(forSnapshot(jest.mocked(customerIoPlugin.onEvent!).mock.calls[0][0])).toMatchInlineSnapshot(` | ||
{ | ||
|
@@ -162,13 +185,13 @@ describe('LegacyPluginExecutorService', () => { | |
"email": "[email protected]", | ||
"first_name": "Pumpkin", | ||
}, | ||
"team_id": 1, | ||
"team_id": 2, | ||
"uuid": "uuid", | ||
}, | ||
"properties": { | ||
"email": "[email protected]", | ||
}, | ||
"team_id": 1, | ||
"team_id": 2, | ||
"timestamp": "2025-01-01T00:00:00.000Z", | ||
"uuid": "<REPLACED-UUID-0>", | ||
} | ||
|
@@ -191,7 +214,7 @@ describe('LegacyPluginExecutorService', () => { | |
[ | ||
"https://track.customer.io/api/v1/customers/distinct_id", | ||
{ | ||
"body": "{"identifier":"distinct_id","email":"[email protected]"}", | ||
"body": "{"_update":false,"identifier":"distinct_id","email":"[email protected]"}", | ||
"headers": { | ||
"Authorization": "Basic MTIzNDU2Nzg5MDpjaW8tdG9rZW4=", | ||
"Content-Type": "application/json", | ||
|
@@ -220,9 +243,9 @@ describe('LegacyPluginExecutorService', () => { | |
[ | ||
"Executing plugin plugin-customerio-plugin", | ||
"Successfully authenticated with Customer.io. Completing setupPlugin.", | ||
"Detected email:, [email protected]", | ||
"{"status":{},"email":"[email protected]"}", | ||
"Should customer be tracked:, true", | ||
"Detected email, [email protected]", | ||
"{"status":{},"existsAlready":false,"email":"[email protected]"}", | ||
"true", | ||
"Execution successful", | ||
] | ||
`) | ||
|
@@ -249,11 +272,12 @@ describe('LegacyPluginExecutorService', () => { | |
[ | ||
"Executing plugin plugin-customerio-plugin", | ||
"Successfully authenticated with Customer.io. Completing setupPlugin.", | ||
"Detected email:, [email protected]", | ||
"{"status":{},"email":"[email protected]"}", | ||
"Should customer be tracked:, true", | ||
"Detected email, [email protected]", | ||
"{"status":{},"existsAlready":false,"email":"[email protected]"}", | ||
"true", | ||
"Fetch called but mocked due to test function", | ||
"Plugin execution failed: Received a potentially intermittent error from the Customer.io API. Response 500: {"message":"Test function"}", | ||
"Fetch called but mocked due to test function", | ||
"Execution successful", | ||
] | ||
`) | ||
}) | ||
|
@@ -287,9 +311,9 @@ describe('LegacyPluginExecutorService', () => { | |
[ | ||
"Executing plugin plugin-customerio-plugin", | ||
"Successfully authenticated with Customer.io. Completing setupPlugin.", | ||
"Detected email:, [email protected]", | ||
"{"status":{},"email":"[email protected]"}", | ||
"Should customer be tracked:, true", | ||
"Detected email, [email protected]", | ||
"{"status":{},"existsAlready":false,"email":"[email protected]"}", | ||
"true", | ||
"Plugin execution failed: Received a potentially intermittent error from the Customer.io API. Response 500: {}", | ||
] | ||
`) | ||
|
@@ -342,7 +366,7 @@ describe('LegacyPluginExecutorService', () => { | |
"properties": { | ||
"email": "[email protected]", | ||
}, | ||
"team_id": 1, | ||
"team_id": 2, | ||
"timestamp": "2025-01-01T00:00:00.000Z", | ||
"uuid": "<REPLACED-UUID-0>", | ||
} | ||
|
@@ -394,7 +418,7 @@ describe('LegacyPluginExecutorService', () => { | |
"version__minor": 12, | ||
"version__patch": 20, | ||
}, | ||
"team_id": 1, | ||
"team_id": 2, | ||
"timestamp": "2025-01-01T00:00:00.000Z", | ||
"uuid": "<REPLACED-UUID-0>", | ||
} | ||
|
@@ -441,6 +465,10 @@ describe('LegacyPluginExecutorService', () => { | |
const invocation = buildInvocation(plugin) | ||
invocation.hogFunction.name = name | ||
invocation.globals.event.event = '$identify' // Many plugins filter for this | ||
|
||
if (plugin.template.id === 'plugin-customerio-plugin') { | ||
invocation.globals.inputs.legacy_plugin_config_id = pluginConfig.id | ||
} | ||
const res = await service.execute(invocation) | ||
expect(res.logs.map((l) => l.message)).toMatchSnapshot() | ||
}) | ||
|
@@ -485,26 +513,6 @@ describe('LegacyPluginExecutorService', () => { | |
}) | ||
|
||
it('should succeed if legacy plugin config id is provided', async () => { | ||
console.log(team.id, team.organization_id) | ||
const plugin = await createPlugin(hub.postgres, { | ||
organization_id: team.organization_id, | ||
name: 'first-time-event-tracker', | ||
plugin_type: 'source', | ||
is_global: false, | ||
source__index_ts: ` | ||
export async function runEveryMinute() { | ||
console.info(JSON.stringify(['runEveryMinute'])) | ||
} | ||
`, | ||
}) | ||
const pluginConfig = await createPluginConfig(hub.postgres, { | ||
name: 'first-time-event-tracker', | ||
team_id: team.id, | ||
plugin_id: plugin.id, | ||
} as any) | ||
|
||
console.log(pluginConfig) | ||
|
||
invocation.globals.inputs.legacy_plugin_config_id = pluginConfig.id | ||
|
||
const res = await service.execute(invocation) | ||
|