-
Notifications
You must be signed in to change notification settings - Fork 9k
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
8bafe22
commit ec9d8dd
Showing
2 changed files
with
93 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export const RoleGetResponse = { | ||
id: 1, | ||
name: 'Admin', | ||
preferences: {}, | ||
default_at_signup: false, | ||
active: true, | ||
note: 'To configure your system.', | ||
updated_by_id: 666, | ||
created_by_id: 1, | ||
created_at: '2024-10-08T15:08:25.468Z', | ||
updated_at: '2024-12-12T10:35:41.887Z', | ||
permission_ids: [1, 68, 58, 46], | ||
knowledge_base_permission_ids: [], | ||
group_ids: {}, | ||
}; | ||
|
||
export const RoleCreateResponse = { | ||
id: 2, | ||
name: 'TestRole', | ||
preferences: {}, | ||
default_at_signup: false, | ||
active: true, | ||
note: null, | ||
updated_by_id: 666, | ||
created_by_id: 1, | ||
created_at: '2024-10-08T15:08:25.468Z', | ||
updated_at: '2024-12-12T10:35:41.887Z', | ||
permission_ids: [1, 68, 58, 46], | ||
knowledge_base_permission_ids: [], | ||
group_ids: {}, | ||
}; |
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,62 @@ | ||
import nock from 'nock'; | ||
import axios from 'axios'; | ||
import { Zammad } from '../Zammad.node'; | ||
import { RoleGetResponse, RoleCreateResponse } from './RoleResponses'; | ||
|
||
describe('Zammad Node - resource: role', () => { | ||
beforeAll(() => { | ||
nock.disableNetConnect(); | ||
|
||
// GET /api/v1/roles/1 | ||
nock('https://api.zammad.org/').get('/api/v1/roles/1').reply(200, RoleGetResponse); | ||
}); | ||
|
||
afterAll(() => { | ||
nock.cleanAll(); | ||
nock.enableNetConnect(); | ||
nock.restore(); | ||
}); | ||
|
||
it('should get role "Admin" via the node.execute method', async () => { | ||
const node = new Zammad(); | ||
|
||
const items = [{ json: {} }]; | ||
|
||
const context = { | ||
getInputData: () => items, | ||
|
||
getCredentials: jest.fn().mockResolvedValue({ | ||
baseUrl: 'https://api.zammad.org/', | ||
accessToken: 'testToken', | ||
allowUnauthorizedCerts: false, | ||
}), | ||
|
||
getNodeParameter: (paramName: string, index: number) => { | ||
if (paramName === 'resource') return 'role'; | ||
if (paramName === 'operation') return 'get'; | ||
if (paramName === 'id') return 1; | ||
return undefined; | ||
}, | ||
|
||
continueOnFail: () => false, | ||
|
||
helpers: { | ||
returnJsonArray: (data: any) => [data], | ||
constructExecutionMetaData: (data: any) => data, | ||
request: async (options: any) => { | ||
const response = await axios({ | ||
method: options.method, | ||
url: options.uri, | ||
data: options.body, | ||
headers: options.headers, | ||
validateStatus: () => true, | ||
}); | ||
return response.data; | ||
}, | ||
}, | ||
}; | ||
|
||
const result = await node.execute.call(context as any); | ||
expect(result[0][0].name).toBe('Admin'); | ||
}); | ||
}); |