-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from kontent-ai/decouple_status
Implement importing the function from the statusImpl if it exists,
- Loading branch information
Showing
11 changed files
with
177 additions
and
42 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 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,35 @@ | ||
import { loadStatusPlugin } from '../../utils/status/statusPlugin'; | ||
|
||
describe('status plugin tests', () => { | ||
const saveStatus = () => {}; | ||
const readStatus = () => ({}); | ||
|
||
jest.mock( | ||
'plugin', | ||
() => ({ | ||
saveStatus, | ||
readStatus, | ||
}), | ||
{ virtual: true } | ||
); | ||
|
||
jest.mock( | ||
'malformedPlugin', | ||
() => ({ | ||
save: saveStatus, | ||
read: readStatus, | ||
}), | ||
{ virtual: true } | ||
); | ||
|
||
it('test correct plugin', async () => { | ||
const functions = await loadStatusPlugin('plugin'); | ||
|
||
expect(functions.saveStatus).toEqual(saveStatus); | ||
expect(functions.readStatus).toEqual(readStatus); | ||
}); | ||
|
||
it('test malformed plugin', async () => { | ||
expect(loadStatusPlugin('malformedPlugin')).rejects.toThrow(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import { ManagementClient } from '@kontent-ai/management-sdk'; | ||
import { IStatus } from '../models/status'; | ||
|
||
export declare interface MigrationModule { | ||
readonly order: number | Date; | ||
run(apiClient: ManagementClient): Promise<void>; | ||
} | ||
|
||
export type SaveStatusType = (data: string) => Promise<void>; | ||
export type ReadStatusType = () => Promise<IStatus>; |
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,19 @@ | ||
import { ReadStatusType, SaveStatusType } from '../../types'; | ||
|
||
export interface StatusPlugin { | ||
saveStatus: SaveStatusType; | ||
readStatus: ReadStatusType; | ||
} | ||
|
||
export const loadStatusPlugin = async (path: string): Promise<StatusPlugin> => { | ||
const pluginModule = await import(path); | ||
|
||
if (!('saveStatus' in pluginModule && typeof pluginModule.saveStatus === 'function') || !('readStatus' in pluginModule && typeof pluginModule.readStatus === 'function')) { | ||
throw new Error('Invalid plugin: does not implement saveStatus or readStatus functions'); | ||
} | ||
|
||
return { | ||
saveStatus: pluginModule.saveStatus, | ||
readStatus: pluginModule.readStatus, | ||
}; | ||
}; |
Oops, something went wrong.