Skip to content

Commit

Permalink
First Role Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sirhexalot committed Dec 23, 2024
1 parent 8bafe22 commit ec9d8dd
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/nodes-base/nodes/Zammad/test/RoleResponses.ts
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: {},
};
62 changes: 62 additions & 0 deletions packages/nodes-base/nodes/Zammad/test/Roles.test.ts
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');
});
});

0 comments on commit ec9d8dd

Please sign in to comment.