-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: implemented common useHttp hook * feat: initial entity field group * feat: implemented interaction logic with entity & tests * feat: implemented EntityFieldGroup (WIP) * feat: added entity type parameter to ui definition & updated stories * Bal 3486 (#3034) * feat: added entity creation & deletion endpoints * fix: fixed entity deletion * feat: finalized creation & deletion logic of entities * fix: lock fix * Bal 3487(WIP) (#3036) * feat(workflows-service): implemented document controller, service, repository, and dto * fix(workflows-service): added cascase on delete * refactor(workflows-service): removed uploadFile method from collection flow service * feat(workflows-service): added the ability to reupload document (#3019) * feat: implemented documents upload * feat: reworked creation ui * feat: implemented document creation & deletion * feat: finalized entity group field * fix: fixed tests * fix: cleanup * fix: format fix * fix: fixed build --------- Co-authored-by: Omri Levy <[email protected]> Co-authored-by: Omri Levy <[email protected]> Co-authored-by: Shane <[email protected]> * fix: crypto mock in tests * feat: reworked documentfield & integrated entityfield to kyb & updated enpoints (#3040) * feat: added end user creation skip for created entities in kyb (#3044) * feat: implemented http document deletion on hide & fixed tests (#3045) * feat: implemented sync plugin & fixes (#3047) * fix: format * fix: refactored test * fix: refactor * fix: refactor * fix: updated logging & removed debugger * feat: added external schema for cf document && updated endpoint * fix: replaced id with ballerineEntityId & updated endpoint * fix: fixed test --------- Co-authored-by: Omri Levy <[email protected]> Co-authored-by: Omri Levy <[email protected]> Co-authored-by: Shane <[email protected]>
- Loading branch information
1 parent
86a481a
commit 01ac5db
Showing
94 changed files
with
3,489 additions
and
664 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
2 changes: 2 additions & 0 deletions
2
...ponents/organisms/CollectionFlowUI/components/utility/PluginsRunner/plugins.repository.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
26 changes: 26 additions & 0 deletions
26
...onents/organisms/CollectionFlowUI/components/utility/PluginsRunner/plugins/sync-plugin.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,26 @@ | ||
import { syncContext } from '@/domains/collection-flow'; | ||
import { CollectionFlowContext } from '@/domains/collection-flow/types/flow-context.types'; | ||
import jsonata from 'jsonata'; | ||
import { toast } from 'sonner'; | ||
import { TPluginRunner } from '../types'; | ||
|
||
export const SYNC_PLUGIN_NAME = 'sync'; | ||
|
||
export interface ISyncPluginParams { | ||
transform?: string; | ||
} | ||
|
||
export const syncPlugin: TPluginRunner<ISyncPluginParams> = async (context, _, pluginParams) => { | ||
try { | ||
const syncPayload = pluginParams?.transform | ||
? await jsonata(pluginParams.transform).evaluate(context) | ||
: context; | ||
|
||
await syncContext(syncPayload as CollectionFlowContext); | ||
} catch (error) { | ||
toast.error('Failed to sync using plugin.'); | ||
console.error(error); | ||
} | ||
|
||
return context; | ||
}; |
60 changes: 60 additions & 0 deletions
60
...anisms/CollectionFlowUI/components/utility/PluginsRunner/plugins/sync-plugin.unit.test.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 { syncContext } from '@/domains/collection-flow'; | ||
import { toast } from 'sonner'; | ||
import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
import { SYNC_PLUGIN_NAME, syncPlugin } from './sync-plugin'; | ||
|
||
vi.mock('@/domains/collection-flow', () => ({ | ||
syncContext: vi.fn(), | ||
})); | ||
|
||
vi.mock('sonner', () => ({ | ||
toast: { | ||
error: vi.fn(), | ||
}, | ||
})); | ||
|
||
describe('syncPlugin', () => { | ||
const mockContext = { | ||
someData: 'test', | ||
}; | ||
|
||
const mockedSyncContext = vi.mocked(syncContext); | ||
const mockedToastError = vi.mocked(toast.error); | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('should call syncContext with the provided context', async () => { | ||
await syncPlugin(mockContext, {} as any, {}); | ||
|
||
expect(mockedSyncContext).toHaveBeenCalledTimes(1); | ||
expect(mockedSyncContext).toHaveBeenCalledWith(mockContext); | ||
}); | ||
|
||
it('should return the original context after successful sync', async () => { | ||
const result = await syncPlugin(mockContext, {} as any, {}); | ||
|
||
expect(result).toBe(mockContext); | ||
}); | ||
|
||
it('should handle errors and show toast message', async () => { | ||
const mockError = new Error('Sync failed'); | ||
mockedSyncContext.mockRejectedValueOnce(mockError); | ||
|
||
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); | ||
|
||
const result = await syncPlugin(mockContext, {} as any, {}); | ||
|
||
expect(mockedToastError).toHaveBeenCalledTimes(1); | ||
expect(mockedToastError).toHaveBeenCalledWith('Failed to sync using plugin.'); | ||
expect(consoleSpy).toHaveBeenCalledWith(mockError); | ||
expect(result).toBe(mockContext); | ||
|
||
consoleSpy.mockRestore(); | ||
}); | ||
|
||
it('should have the correct plugin name exported', () => { | ||
expect(SYNC_PLUGIN_NAME).toBe('sync'); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './types'; | ||
export * from './useHttp'; | ||
export * from './utils/format-headers'; | ||
export * from './utils/request'; |
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,7 @@ | ||
export interface IHttpParams { | ||
url: string; | ||
resultPath: string; | ||
headers?: Record<string, string>; | ||
method?: 'POST' | 'PUT' | 'GET' | 'DELETE'; | ||
timeout?: number; | ||
} |
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,50 @@ | ||
import { AnyObject } from '@/common/types'; | ||
import get from 'lodash/get'; | ||
import { useCallback, useState } from 'react'; | ||
import { IHttpParams } from './types'; | ||
import { request } from './utils/request'; | ||
|
||
export const useHttp = (params: IHttpParams, metadata: AnyObject) => { | ||
const [responseError, setResponseError] = useState<Error | null>(null); | ||
const [isLoading, setIsLoading] = useState(false); | ||
|
||
const runRequest = useCallback( | ||
async ( | ||
requestPayload?: any, | ||
other?: { | ||
params?: AnyObject; | ||
}, | ||
) => { | ||
setIsLoading(true); | ||
setResponseError(null); | ||
|
||
try { | ||
const response = await request( | ||
{ | ||
...params, | ||
url: params.url, | ||
}, | ||
metadata, | ||
requestPayload, | ||
other?.params, | ||
); | ||
|
||
return params.resultPath ? get(response, params.resultPath) : response; | ||
} catch (error) { | ||
console.error(error); | ||
setResponseError(error as Error); | ||
|
||
throw error; | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}, | ||
[params, metadata], | ||
); | ||
|
||
return { | ||
isLoading, | ||
error: responseError, | ||
run: runRequest, | ||
}; | ||
}; |
Oops, something went wrong.