-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
6 changed files
with
96 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import axios from 'axios'; | ||
|
||
import { RunWorkflowFromEntity, WorkflowFromEntity } from 'types/workflow'; | ||
import { ClientType, Options } from '../../index'; | ||
|
||
import { RUN_WORKFLOW_FROM_ENTITY } from 'mutations/workflow'; | ||
|
||
export class Workflow { | ||
protected axiosClient: any; | ||
constructor(protected client: ClientType, protected options?: Options) { | ||
if (this.options) { | ||
this.axiosClient = axios.create({ | ||
baseURL: this.options.url, | ||
headers: { | ||
'X-Kanvas-App': this.options.key, | ||
...(this.options.adminKey && { | ||
'X-Kanvas-Key': this.options.adminKey, | ||
}), | ||
}, | ||
}); | ||
|
||
this.axiosClient.interceptors.request.use( | ||
this.options.authAxiosMiddleware, | ||
function (error: any) { | ||
return Promise.reject(error); | ||
} | ||
); | ||
} | ||
} | ||
|
||
public async runWorkflowFromEntity( | ||
input: WorkflowFromEntity | ||
): Promise<RunWorkflowFromEntity> { | ||
const response = await this.client.mutate({ | ||
mutation: RUN_WORKFLOW_FROM_ENTITY, | ||
variables: { input: input } | ||
}); | ||
|
||
return response.data; | ||
} | ||
} |
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 @@ | ||
import { gql } from '@apollo/client/core'; | ||
|
||
export const RUN_WORKFLOW_FROM_ENTITY = gql` | ||
mutation runWorkflowEntityInput($input: runWorkflowEntityInput!) { | ||
runWorkflowFromEntity(input: $input) | ||
} | ||
`; |
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,13 @@ | ||
|
||
export interface WorkflowFromEntity { | ||
entity_namespace: string; | ||
entity_id: string; | ||
action: string; | ||
params?: any; | ||
} | ||
|
||
export interface RunWorkflowFromEntity { | ||
runWorkflowFromEntity: { | ||
[key: string]: any; // Allow any structure within the response | ||
}; | ||
} |
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,31 @@ | ||
import { initializeClient, getClient } from './setupClient'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
beforeAll(async () => { | ||
await initializeClient(process.env.KANVAS_APP_SECRET!); | ||
}); | ||
|
||
/** | ||
* @todo add profile photo upload test | ||
*/ | ||
describe('Test the Kanvas Workflow', () => { | ||
|
||
it('run workflow', async () => { | ||
const client = getClient(); | ||
|
||
const workflow = await client.workflow.runWorkflowFromEntity({ | ||
entity_namespace: 'user', | ||
entity_id: '2', | ||
action: 'updated', | ||
params: { | ||
name: 'John Doe', | ||
} | ||
}); | ||
|
||
expect(workflow).toBeDefined(); | ||
expect(workflow.runWorkflowFromEntity).toBeDefined(); | ||
expect(workflow.runWorkflowFromEntity.success).toBeTruthy(); | ||
}); | ||
}); |