Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c0f0415f70 | ||
![]() |
23c40c89ee | ||
![]() |
77f84944c7 | ||
![]() |
8a8be21d56 | ||
![]() |
e5c4e18fd5 | ||
![]() |
953c5a5b5b | ||
![]() |
4313265c00 | ||
![]() |
9405f267ba | ||
![]() |
1d29238199 | ||
![]() |
c5bf66f462 | ||
![]() |
e6180bdfaa | ||
![]() |
55c391afc8 | ||
![]() |
782fa67320 |
@@ -6,8 +6,7 @@
|
|||||||
"start": "lerna run --stream --parallel --scope=@*/{web,backend} dev",
|
"start": "lerna run --stream --parallel --scope=@*/{web,backend} dev",
|
||||||
"start:web": "lerna run --stream --scope=@*/web dev",
|
"start:web": "lerna run --stream --scope=@*/web dev",
|
||||||
"start:backend": "lerna run --stream --scope=@*/backend dev",
|
"start:backend": "lerna run --stream --scope=@*/backend dev",
|
||||||
"lint": "lerna run --no-bail --stream --parallel --scope=@*/{web,backend,cli} lint",
|
"lint": "lerna run --no-bail --stream --parallel --scope=@*/{web,backend} lint",
|
||||||
"build:watch": "lerna run --no-bail --stream --parallel --scope=@*/{web,backend,cli} build:watch",
|
|
||||||
"build:docs": "cd ./packages/docs && yarn install && yarn build"
|
"build:docs": "cd ./packages/docs && yarn install && yarn build"
|
||||||
},
|
},
|
||||||
"workspaces": {
|
"workspaces": {
|
||||||
|
@@ -0,0 +1,43 @@
|
|||||||
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
|
export default defineAction({
|
||||||
|
name: 'Acknowledge incident',
|
||||||
|
key: 'acknowledgeIncident',
|
||||||
|
description: 'Acknowledges an incident.',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Incident ID',
|
||||||
|
key: 'incidentId',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
variables: true,
|
||||||
|
description:
|
||||||
|
'This serves as the incident ID that requires your acknowledgment.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Acknowledged by',
|
||||||
|
key: 'acknowledgedBy',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
variables: true,
|
||||||
|
description:
|
||||||
|
"This refers to the individual's name, email, or another form of identification that the person who acknowledged the incident has provided.",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const acknowledgedBy = $.step.parameters.acknowledgedBy;
|
||||||
|
const incidentId = $.step.parameters.incidentId;
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
acknowledged_by: acknowledgedBy,
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await $.http.post(
|
||||||
|
`/v2/incidents/${incidentId}/acknowledge`,
|
||||||
|
body
|
||||||
|
);
|
||||||
|
|
||||||
|
$.setActionItem({ raw: response.data.data });
|
||||||
|
},
|
||||||
|
});
|
@@ -0,0 +1,120 @@
|
|||||||
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
|
export default defineAction({
|
||||||
|
name: 'Create incident',
|
||||||
|
key: 'createIncident',
|
||||||
|
description: 'Creates an incident that informs the team.',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Brief Summary',
|
||||||
|
key: 'briefSummary',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
variables: true,
|
||||||
|
description: 'A short description outlining the issue.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Description',
|
||||||
|
key: 'description',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
variables: true,
|
||||||
|
description:
|
||||||
|
'An elaborate description of the situation, offering insights into what is occurring, along with instructions to reproduce the problem.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Requester Email',
|
||||||
|
key: 'requesterEmail',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
variables: true,
|
||||||
|
description:
|
||||||
|
'This represents the email address of the individual who initiated the incident request.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Alert Settings - Call',
|
||||||
|
key: 'alertSettingsCall',
|
||||||
|
type: 'dropdown',
|
||||||
|
required: true,
|
||||||
|
description: 'Should we call the on-call person?',
|
||||||
|
variables: true,
|
||||||
|
options: [
|
||||||
|
{ label: 'Yes', value: 'true' },
|
||||||
|
{ label: 'No', value: 'false' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Alert Settings - Text',
|
||||||
|
key: 'alertSettingsText',
|
||||||
|
type: 'dropdown',
|
||||||
|
required: true,
|
||||||
|
description: 'Should we text the on-call person?',
|
||||||
|
variables: true,
|
||||||
|
options: [
|
||||||
|
{ label: 'Yes', value: 'true' },
|
||||||
|
{ label: 'No', value: 'false' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Alert Settings - Email',
|
||||||
|
key: 'alertSettingsEmail',
|
||||||
|
type: 'dropdown',
|
||||||
|
required: true,
|
||||||
|
description: 'Should we email the on-call person?',
|
||||||
|
variables: true,
|
||||||
|
options: [
|
||||||
|
{ label: 'Yes', value: 'true' },
|
||||||
|
{ label: 'No', value: 'false' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Alert Settings - Push Notification',
|
||||||
|
key: 'alertSettingsPushNotification',
|
||||||
|
type: 'dropdown',
|
||||||
|
required: true,
|
||||||
|
description: 'Should we send a push notification to the on-call person?',
|
||||||
|
variables: true,
|
||||||
|
options: [
|
||||||
|
{ label: 'Yes', value: 'true' },
|
||||||
|
{ label: 'No', value: 'false' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Team Alert Wait Time',
|
||||||
|
key: 'teamAlertWaitTime',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
variables: true,
|
||||||
|
description:
|
||||||
|
"What is the time threshold for acknowledgment before escalating to the entire team? (Specify in seconds) - Use a negative value to indicate no team alert if the on-call person doesn't respond, and use 0 for an immediate alert to the entire team.",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const {
|
||||||
|
briefSummary,
|
||||||
|
description,
|
||||||
|
requesterEmail,
|
||||||
|
alertSettingsCall,
|
||||||
|
alertSettingsText,
|
||||||
|
alertSettingsEmail,
|
||||||
|
alertSettingsPushNotification,
|
||||||
|
teamAlertWaitTime,
|
||||||
|
} = $.step.parameters;
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
summary: briefSummary,
|
||||||
|
description,
|
||||||
|
requester_email: requesterEmail,
|
||||||
|
call: alertSettingsCall,
|
||||||
|
sms: alertSettingsText,
|
||||||
|
email: alertSettingsEmail,
|
||||||
|
push: alertSettingsPushNotification,
|
||||||
|
team_wait: teamAlertWaitTime,
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await $.http.post('/v2/incidents', body);
|
||||||
|
|
||||||
|
$.setActionItem({ raw: response.data.data });
|
||||||
|
},
|
||||||
|
});
|
5
packages/backend/src/apps/better-stack/actions/index.js
Normal file
5
packages/backend/src/apps/better-stack/actions/index.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import acknowledgeIncident from './acknowledge-incident/index.js';
|
||||||
|
import createIncident from './create-incident/index.js';
|
||||||
|
import resolveIncident from './resolve-incident/index.js';
|
||||||
|
|
||||||
|
export default [acknowledgeIncident, createIncident, resolveIncident];
|
@@ -0,0 +1,43 @@
|
|||||||
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
|
export default defineAction({
|
||||||
|
name: 'Resolve incident',
|
||||||
|
key: 'resolveIncident',
|
||||||
|
description: 'Resolves an incident.',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Incident ID',
|
||||||
|
key: 'incidentId',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
variables: true,
|
||||||
|
description:
|
||||||
|
'This represents the identification for an incident that requires resolution.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Resolved by',
|
||||||
|
key: 'resolvedBy',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
variables: true,
|
||||||
|
description:
|
||||||
|
"This refers to the individual's name, email, or another form of identification that the person who resolved the incident has provided.",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const resolvedBy = $.step.parameters.resolvedBy;
|
||||||
|
const incidentId = $.step.parameters.incidentId;
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
resolved_by: resolvedBy,
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await $.http.post(
|
||||||
|
`/v2/incidents/${incidentId}/resolve`,
|
||||||
|
body
|
||||||
|
);
|
||||||
|
|
||||||
|
$.setActionItem({ raw: response.data.data });
|
||||||
|
},
|
||||||
|
});
|
21
packages/backend/src/apps/better-stack/assets/favicon.svg
Normal file
21
packages/backend/src/apps/better-stack/assets/favicon.svg
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" standalone="no"?>
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
||||||
|
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||||
|
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="200.000000pt" height="200.000000pt" viewBox="0 0 200.000000 200.000000"
|
||||||
|
preserveAspectRatio="xMidYMid meet">
|
||||||
|
|
||||||
|
<g transform="translate(0.000000,200.000000) scale(0.100000,-0.100000)"
|
||||||
|
fill="#000" stroke="none">
|
||||||
|
<path d="M0 1000 l0 -1000 1000 0 1000 0 0 1000 0 1000 -1000 0 -1000 0 0
|
||||||
|
-1000z m1162 460 c14 -11 113 -184 232 -408 228 -429 231 -439 175 -486 -35
|
||||||
|
-30 -30 -29 -140 -15 -89 12 -123 25 -152 56 -9 11 -72 147 -140 304 -113 263
|
||||||
|
-124 284 -149 287 -14 2 -29 10 -32 17 -8 21 67 214 94 242 28 29 78 30 112 3z
|
||||||
|
m-340 -148 c10 -10 72 -175 139 -367 114 -325 121 -351 108 -374 -8 -14 -27
|
||||||
|
-32 -41 -41 -25 -13 -34 -12 -126 18 -55 18 -111 43 -125 56 -19 17 -40 67
|
||||||
|
-76 182 -36 112 -58 164 -73 176 l-22 16 27 99 c63 224 66 232 95 248 31 17
|
||||||
|
69 12 94 -13z m-314 -219 c16 -15 26 -59 56 -243 42 -262 43 -285 17 -300 -11
|
||||||
|
-5 -24 -10 -30 -10 -19 0 -140 114 -150 141 -7 20 -4 76 10 191 10 90 19 171
|
||||||
|
19 181 0 18 33 57 49 57 5 0 18 -8 29 -17z"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.1 KiB |
33
packages/backend/src/apps/better-stack/auth/index.js
Normal file
33
packages/backend/src/apps/better-stack/auth/index.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import verifyCredentials from './verify-credentials.js';
|
||||||
|
import isStillVerified from './is-still-verified.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
key: 'screenName',
|
||||||
|
label: 'Screen Name',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
readOnly: false,
|
||||||
|
value: null,
|
||||||
|
placeholder: null,
|
||||||
|
description:
|
||||||
|
'Screen name of your connection to be used on Automatisch UI.',
|
||||||
|
clickToCopy: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'apiKey',
|
||||||
|
label: 'API Key',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
readOnly: false,
|
||||||
|
value: null,
|
||||||
|
placeholder: null,
|
||||||
|
description: 'Better Stack API key of your account.',
|
||||||
|
clickToCopy: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
verifyCredentials,
|
||||||
|
isStillVerified,
|
||||||
|
};
|
@@ -0,0 +1,8 @@
|
|||||||
|
import verifyCredentials from './verify-credentials.js';
|
||||||
|
|
||||||
|
const isStillVerified = async ($) => {
|
||||||
|
await verifyCredentials($);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default isStillVerified;
|
@@ -0,0 +1,10 @@
|
|||||||
|
const verifyCredentials = async ($) => {
|
||||||
|
await $.http.get('/v2/metadata');
|
||||||
|
|
||||||
|
await $.auth.set({
|
||||||
|
screenName: $.auth.data.screenName,
|
||||||
|
apiKey: $.auth.data.apiKey,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export default verifyCredentials;
|
@@ -0,0 +1,9 @@
|
|||||||
|
const addAuthHeader = ($, requestConfig) => {
|
||||||
|
if ($.auth.data?.apiKey) {
|
||||||
|
requestConfig.headers.Authorization = `Bearer ${$.auth.data.apiKey}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return requestConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default addAuthHeader;
|
18
packages/backend/src/apps/better-stack/index.js
Normal file
18
packages/backend/src/apps/better-stack/index.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import defineApp from '../../helpers/define-app.js';
|
||||||
|
import addAuthHeader from './common/add-auth-header.js';
|
||||||
|
import auth from './auth/index.js';
|
||||||
|
import actions from './actions/index.js';
|
||||||
|
|
||||||
|
export default defineApp({
|
||||||
|
name: 'Better Stack',
|
||||||
|
key: 'better-stack',
|
||||||
|
iconUrl: '{BASE_URL}/apps/better-stack/assets/favicon.svg',
|
||||||
|
authDocUrl: 'https://automatisch.io/docs/apps/better-stack/connection',
|
||||||
|
supportsConnections: true,
|
||||||
|
baseUrl: 'https://betterstack.com',
|
||||||
|
apiBaseUrl: 'https://uptime.betterstack.com/api',
|
||||||
|
primaryColor: '000000',
|
||||||
|
beforeRequest: [addAuthHeader],
|
||||||
|
auth,
|
||||||
|
actions,
|
||||||
|
});
|
@@ -6,100 +6,74 @@ import { createRole } from '../../../test/factories/role';
|
|||||||
import { createUser } from '../../../test/factories/user';
|
import { createUser } from '../../../test/factories/user';
|
||||||
|
|
||||||
describe('graphQL getCurrentUser query', () => {
|
describe('graphQL getCurrentUser query', () => {
|
||||||
describe('with unauthenticated user', () => {
|
let role, currentUser, token, requestObject;
|
||||||
it('should throw not authorized error', async () => {
|
|
||||||
const invalidUserToken = 'invalid-token';
|
|
||||||
|
|
||||||
const query = `
|
beforeEach(async () => {
|
||||||
query {
|
role = await createRole({
|
||||||
getCurrentUser {
|
key: 'sample',
|
||||||
id
|
name: 'sample',
|
||||||
email
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const response = await request(app)
|
|
||||||
.post('/graphql')
|
|
||||||
.set('Authorization', invalidUserToken)
|
|
||||||
.send({ query })
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
|
||||||
expect(response.body.errors[0].message).toEqual('Not Authorised!');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
currentUser = await createUser({
|
||||||
|
roleId: role.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
token = createAuthTokenByUserId(currentUser.id);
|
||||||
|
requestObject = request(app).post('/graphql').set('Authorization', token);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with authenticated user', () => {
|
it('should return user data', async () => {
|
||||||
let role, currentUser, token, requestObject;
|
const query = `
|
||||||
|
query {
|
||||||
beforeEach(async () => {
|
getCurrentUser {
|
||||||
role = await createRole({
|
id
|
||||||
key: 'sample',
|
email
|
||||||
name: 'sample',
|
fullName
|
||||||
});
|
email
|
||||||
|
createdAt
|
||||||
currentUser = await createUser({
|
updatedAt
|
||||||
roleId: role.id,
|
role {
|
||||||
});
|
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
requestObject = request(app).post('/graphql').set('Authorization', token);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return user data', async () => {
|
|
||||||
const query = `
|
|
||||||
query {
|
|
||||||
getCurrentUser {
|
|
||||||
id
|
id
|
||||||
email
|
name
|
||||||
fullName
|
|
||||||
email
|
|
||||||
createdAt
|
|
||||||
updatedAt
|
|
||||||
role {
|
|
||||||
id
|
|
||||||
name
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
const response = await requestObject.send({ query }).expect(200);
|
const response = await requestObject.send({ query }).expect(200);
|
||||||
|
|
||||||
const expectedResponsePayload = {
|
const expectedResponsePayload = {
|
||||||
data: {
|
data: {
|
||||||
getCurrentUser: {
|
getCurrentUser: {
|
||||||
createdAt: currentUser.createdAt.getTime().toString(),
|
createdAt: currentUser.createdAt.getTime().toString(),
|
||||||
email: currentUser.email,
|
email: currentUser.email,
|
||||||
fullName: currentUser.fullName,
|
fullName: currentUser.fullName,
|
||||||
id: currentUser.id,
|
id: currentUser.id,
|
||||||
role: { id: role.id, name: role.name },
|
role: { id: role.id, name: role.name },
|
||||||
updatedAt: currentUser.updatedAt.getTime().toString(),
|
updatedAt: currentUser.updatedAt.getTime().toString(),
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
},
|
||||||
|
};
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedResponsePayload);
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not return user password', async () => {
|
it('should not return user password', async () => {
|
||||||
const query = `
|
const query = `
|
||||||
query {
|
query {
|
||||||
getCurrentUser {
|
getCurrentUser {
|
||||||
id
|
id
|
||||||
email
|
email
|
||||||
password
|
password
|
||||||
}
|
|
||||||
}
|
}
|
||||||
`;
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
const response = await requestObject.send({ query }).expect(400);
|
const response = await requestObject.send({ query }).expect(400);
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
expect(response.body.errors).toBeDefined();
|
||||||
expect(response.body.errors[0].message).toEqual(
|
expect(response.body.errors[0].message).toEqual(
|
||||||
'Cannot query field "password" on type "User".'
|
'Cannot query field "password" on type "User".'
|
||||||
);
|
);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -40,307 +40,291 @@ describe('graphQL getExecutions query', () => {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const invalidToken = 'invalid-token';
|
describe('and without correct permissions', () => {
|
||||||
|
|
||||||
describe('with unauthenticated user', () => {
|
|
||||||
it('should throw not authorized error', async () => {
|
it('should throw not authorized error', async () => {
|
||||||
|
const userWithoutPermissions = await createUser();
|
||||||
|
const token = createAuthTokenByUserId(userWithoutPermissions.id);
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post('/graphql')
|
.post('/graphql')
|
||||||
.set('Authorization', invalidToken)
|
.set('Authorization', token)
|
||||||
.send({ query })
|
.send({ query })
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
expect(response.body.errors).toBeDefined();
|
||||||
expect(response.body.errors[0].message).toEqual('Not Authorised!');
|
expect(response.body.errors[0].message).toEqual('Not authorized!');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with authenticated user', () => {
|
describe('and with correct permission', () => {
|
||||||
describe('and without permissions', () => {
|
let role,
|
||||||
it('should throw not authorized error', async () => {
|
currentUser,
|
||||||
const userWithoutPermissions = await createUser();
|
anotherUser,
|
||||||
const token = createAuthTokenByUserId(userWithoutPermissions.id);
|
token,
|
||||||
|
flowOne,
|
||||||
|
stepOneForFlowOne,
|
||||||
|
stepTwoForFlowOne,
|
||||||
|
executionOne,
|
||||||
|
flowTwo,
|
||||||
|
stepOneForFlowTwo,
|
||||||
|
stepTwoForFlowTwo,
|
||||||
|
executionTwo,
|
||||||
|
flowThree,
|
||||||
|
stepOneForFlowThree,
|
||||||
|
stepTwoForFlowThree,
|
||||||
|
executionThree,
|
||||||
|
expectedResponseForExecutionOne,
|
||||||
|
expectedResponseForExecutionTwo,
|
||||||
|
expectedResponseForExecutionThree;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
role = await createRole({
|
||||||
|
key: 'sample',
|
||||||
|
name: 'sample',
|
||||||
|
});
|
||||||
|
|
||||||
|
currentUser = await createUser({
|
||||||
|
roleId: role.id,
|
||||||
|
fullName: 'Current User',
|
||||||
|
});
|
||||||
|
|
||||||
|
anotherUser = await createUser();
|
||||||
|
|
||||||
|
token = createAuthTokenByUserId(currentUser.id);
|
||||||
|
|
||||||
|
flowOne = await createFlow({
|
||||||
|
userId: currentUser.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
stepOneForFlowOne = await createStep({
|
||||||
|
flowId: flowOne.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
stepTwoForFlowOne = await createStep({
|
||||||
|
flowId: flowOne.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
executionOne = await createExecution({
|
||||||
|
flowId: flowOne.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
await createExecutionStep({
|
||||||
|
executionId: executionOne.id,
|
||||||
|
stepId: stepOneForFlowOne.id,
|
||||||
|
status: 'success',
|
||||||
|
});
|
||||||
|
|
||||||
|
await createExecutionStep({
|
||||||
|
executionId: executionOne.id,
|
||||||
|
stepId: stepTwoForFlowOne.id,
|
||||||
|
status: 'success',
|
||||||
|
});
|
||||||
|
|
||||||
|
flowTwo = await createFlow({
|
||||||
|
userId: currentUser.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
stepOneForFlowTwo = await createStep({
|
||||||
|
flowId: flowTwo.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
stepTwoForFlowTwo = await createStep({
|
||||||
|
flowId: flowTwo.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
executionTwo = await createExecution({
|
||||||
|
flowId: flowTwo.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
await createExecutionStep({
|
||||||
|
executionId: executionTwo.id,
|
||||||
|
stepId: stepOneForFlowTwo.id,
|
||||||
|
status: 'success',
|
||||||
|
});
|
||||||
|
|
||||||
|
await createExecutionStep({
|
||||||
|
executionId: executionTwo.id,
|
||||||
|
stepId: stepTwoForFlowTwo.id,
|
||||||
|
status: 'failure',
|
||||||
|
});
|
||||||
|
|
||||||
|
flowThree = await createFlow({
|
||||||
|
userId: anotherUser.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
stepOneForFlowThree = await createStep({
|
||||||
|
flowId: flowThree.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
stepTwoForFlowThree = await createStep({
|
||||||
|
flowId: flowThree.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
executionThree = await createExecution({
|
||||||
|
flowId: flowThree.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
await createExecutionStep({
|
||||||
|
executionId: executionThree.id,
|
||||||
|
stepId: stepOneForFlowThree.id,
|
||||||
|
status: 'success',
|
||||||
|
});
|
||||||
|
|
||||||
|
await createExecutionStep({
|
||||||
|
executionId: executionThree.id,
|
||||||
|
stepId: stepTwoForFlowThree.id,
|
||||||
|
status: 'failure',
|
||||||
|
});
|
||||||
|
|
||||||
|
expectedResponseForExecutionOne = {
|
||||||
|
node: {
|
||||||
|
createdAt: executionOne.createdAt.getTime().toString(),
|
||||||
|
flow: {
|
||||||
|
active: flowOne.active,
|
||||||
|
id: flowOne.id,
|
||||||
|
name: flowOne.name,
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
iconUrl: `${appConfig.baseUrl}/apps/${stepOneForFlowOne.appKey}/assets/favicon.svg`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
iconUrl: `${appConfig.baseUrl}/apps/${stepTwoForFlowOne.appKey}/assets/favicon.svg`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
id: executionOne.id,
|
||||||
|
status: 'success',
|
||||||
|
testRun: executionOne.testRun,
|
||||||
|
updatedAt: executionOne.updatedAt.getTime().toString(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expectedResponseForExecutionTwo = {
|
||||||
|
node: {
|
||||||
|
createdAt: executionTwo.createdAt.getTime().toString(),
|
||||||
|
flow: {
|
||||||
|
active: flowTwo.active,
|
||||||
|
id: flowTwo.id,
|
||||||
|
name: flowTwo.name,
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
iconUrl: `${appConfig.baseUrl}/apps/${stepTwoForFlowTwo.appKey}/assets/favicon.svg`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
iconUrl: `${appConfig.baseUrl}/apps/${stepTwoForFlowTwo.appKey}/assets/favicon.svg`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
id: executionTwo.id,
|
||||||
|
status: 'failure',
|
||||||
|
testRun: executionTwo.testRun,
|
||||||
|
updatedAt: executionTwo.updatedAt.getTime().toString(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expectedResponseForExecutionThree = {
|
||||||
|
node: {
|
||||||
|
createdAt: executionThree.createdAt.getTime().toString(),
|
||||||
|
flow: {
|
||||||
|
active: flowThree.active,
|
||||||
|
id: flowThree.id,
|
||||||
|
name: flowThree.name,
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
iconUrl: `${appConfig.baseUrl}/apps/${stepOneForFlowThree.appKey}/assets/favicon.svg`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
iconUrl: `${appConfig.baseUrl}/apps/${stepTwoForFlowThree.appKey}/assets/favicon.svg`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
id: executionThree.id,
|
||||||
|
status: 'failure',
|
||||||
|
testRun: executionThree.testRun,
|
||||||
|
updatedAt: executionThree.updatedAt.getTime().toString(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and with isCreator condition', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await createPermission({
|
||||||
|
action: 'read',
|
||||||
|
subject: 'Execution',
|
||||||
|
roleId: role.id,
|
||||||
|
conditions: ['isCreator'],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return executions data of the current user', async () => {
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post('/graphql')
|
.post('/graphql')
|
||||||
.set('Authorization', token)
|
.set('Authorization', token)
|
||||||
.send({ query })
|
.send({ query })
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
const expectedResponsePayload = {
|
||||||
expect(response.body.errors[0].message).toEqual('Not authorized!');
|
data: {
|
||||||
|
getExecutions: {
|
||||||
|
edges: [
|
||||||
|
expectedResponseForExecutionTwo,
|
||||||
|
expectedResponseForExecutionOne,
|
||||||
|
],
|
||||||
|
pageInfo: { currentPage: 1, totalPages: 1 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('and with correct permission', () => {
|
describe('and without isCreator condition', () => {
|
||||||
let role,
|
|
||||||
currentUser,
|
|
||||||
anotherUser,
|
|
||||||
token,
|
|
||||||
flowOne,
|
|
||||||
stepOneForFlowOne,
|
|
||||||
stepTwoForFlowOne,
|
|
||||||
executionOne,
|
|
||||||
flowTwo,
|
|
||||||
stepOneForFlowTwo,
|
|
||||||
stepTwoForFlowTwo,
|
|
||||||
executionTwo,
|
|
||||||
flowThree,
|
|
||||||
stepOneForFlowThree,
|
|
||||||
stepTwoForFlowThree,
|
|
||||||
executionThree,
|
|
||||||
expectedResponseForExecutionOne,
|
|
||||||
expectedResponseForExecutionTwo,
|
|
||||||
expectedResponseForExecutionThree;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
role = await createRole({
|
await createPermission({
|
||||||
key: 'sample',
|
action: 'read',
|
||||||
name: 'sample',
|
subject: 'Execution',
|
||||||
});
|
|
||||||
|
|
||||||
currentUser = await createUser({
|
|
||||||
roleId: role.id,
|
roleId: role.id,
|
||||||
fullName: 'Current User',
|
conditions: [],
|
||||||
});
|
|
||||||
|
|
||||||
anotherUser = await createUser();
|
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
|
|
||||||
flowOne = await createFlow({
|
|
||||||
userId: currentUser.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
stepOneForFlowOne = await createStep({
|
|
||||||
flowId: flowOne.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
stepTwoForFlowOne = await createStep({
|
|
||||||
flowId: flowOne.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
executionOne = await createExecution({
|
|
||||||
flowId: flowOne.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
await createExecutionStep({
|
|
||||||
executionId: executionOne.id,
|
|
||||||
stepId: stepOneForFlowOne.id,
|
|
||||||
status: 'success',
|
|
||||||
});
|
|
||||||
|
|
||||||
await createExecutionStep({
|
|
||||||
executionId: executionOne.id,
|
|
||||||
stepId: stepTwoForFlowOne.id,
|
|
||||||
status: 'success',
|
|
||||||
});
|
|
||||||
|
|
||||||
flowTwo = await createFlow({
|
|
||||||
userId: currentUser.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
stepOneForFlowTwo = await createStep({
|
|
||||||
flowId: flowTwo.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
stepTwoForFlowTwo = await createStep({
|
|
||||||
flowId: flowTwo.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
executionTwo = await createExecution({
|
|
||||||
flowId: flowTwo.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
await createExecutionStep({
|
|
||||||
executionId: executionTwo.id,
|
|
||||||
stepId: stepOneForFlowTwo.id,
|
|
||||||
status: 'success',
|
|
||||||
});
|
|
||||||
|
|
||||||
await createExecutionStep({
|
|
||||||
executionId: executionTwo.id,
|
|
||||||
stepId: stepTwoForFlowTwo.id,
|
|
||||||
status: 'failure',
|
|
||||||
});
|
|
||||||
|
|
||||||
flowThree = await createFlow({
|
|
||||||
userId: anotherUser.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
stepOneForFlowThree = await createStep({
|
|
||||||
flowId: flowThree.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
stepTwoForFlowThree = await createStep({
|
|
||||||
flowId: flowThree.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
executionThree = await createExecution({
|
|
||||||
flowId: flowThree.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
await createExecutionStep({
|
|
||||||
executionId: executionThree.id,
|
|
||||||
stepId: stepOneForFlowThree.id,
|
|
||||||
status: 'success',
|
|
||||||
});
|
|
||||||
|
|
||||||
await createExecutionStep({
|
|
||||||
executionId: executionThree.id,
|
|
||||||
stepId: stepTwoForFlowThree.id,
|
|
||||||
status: 'failure',
|
|
||||||
});
|
|
||||||
|
|
||||||
expectedResponseForExecutionOne = {
|
|
||||||
node: {
|
|
||||||
createdAt: executionOne.createdAt.getTime().toString(),
|
|
||||||
flow: {
|
|
||||||
active: flowOne.active,
|
|
||||||
id: flowOne.id,
|
|
||||||
name: flowOne.name,
|
|
||||||
steps: [
|
|
||||||
{
|
|
||||||
iconUrl: `${appConfig.baseUrl}/apps/${stepOneForFlowOne.appKey}/assets/favicon.svg`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
iconUrl: `${appConfig.baseUrl}/apps/${stepTwoForFlowOne.appKey}/assets/favicon.svg`,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
id: executionOne.id,
|
|
||||||
status: 'success',
|
|
||||||
testRun: executionOne.testRun,
|
|
||||||
updatedAt: executionOne.updatedAt.getTime().toString(),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
expectedResponseForExecutionTwo = {
|
|
||||||
node: {
|
|
||||||
createdAt: executionTwo.createdAt.getTime().toString(),
|
|
||||||
flow: {
|
|
||||||
active: flowTwo.active,
|
|
||||||
id: flowTwo.id,
|
|
||||||
name: flowTwo.name,
|
|
||||||
steps: [
|
|
||||||
{
|
|
||||||
iconUrl: `${appConfig.baseUrl}/apps/${stepTwoForFlowTwo.appKey}/assets/favicon.svg`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
iconUrl: `${appConfig.baseUrl}/apps/${stepTwoForFlowTwo.appKey}/assets/favicon.svg`,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
id: executionTwo.id,
|
|
||||||
status: 'failure',
|
|
||||||
testRun: executionTwo.testRun,
|
|
||||||
updatedAt: executionTwo.updatedAt.getTime().toString(),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
expectedResponseForExecutionThree = {
|
|
||||||
node: {
|
|
||||||
createdAt: executionThree.createdAt.getTime().toString(),
|
|
||||||
flow: {
|
|
||||||
active: flowThree.active,
|
|
||||||
id: flowThree.id,
|
|
||||||
name: flowThree.name,
|
|
||||||
steps: [
|
|
||||||
{
|
|
||||||
iconUrl: `${appConfig.baseUrl}/apps/${stepOneForFlowThree.appKey}/assets/favicon.svg`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
iconUrl: `${appConfig.baseUrl}/apps/${stepTwoForFlowThree.appKey}/assets/favicon.svg`,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
id: executionThree.id,
|
|
||||||
status: 'failure',
|
|
||||||
testRun: executionThree.testRun,
|
|
||||||
updatedAt: executionThree.updatedAt.getTime().toString(),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('and with isCreator condition', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
await createPermission({
|
|
||||||
action: 'read',
|
|
||||||
subject: 'Execution',
|
|
||||||
roleId: role.id,
|
|
||||||
conditions: ['isCreator'],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return executions data of the current user', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.post('/graphql')
|
|
||||||
.set('Authorization', token)
|
|
||||||
.send({ query })
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedResponsePayload = {
|
|
||||||
data: {
|
|
||||||
getExecutions: {
|
|
||||||
edges: [
|
|
||||||
expectedResponseForExecutionTwo,
|
|
||||||
expectedResponseForExecutionOne,
|
|
||||||
],
|
|
||||||
pageInfo: { currentPage: 1, totalPages: 1 },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedResponsePayload);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('and without isCreator condition', () => {
|
it('should return executions data of all users', async () => {
|
||||||
beforeEach(async () => {
|
const response = await request(app)
|
||||||
await createPermission({
|
.post('/graphql')
|
||||||
action: 'read',
|
.set('Authorization', token)
|
||||||
subject: 'Execution',
|
.send({ query })
|
||||||
roleId: role.id,
|
.expect(200);
|
||||||
conditions: [],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return executions data of all users', async () => {
|
const expectedResponsePayload = {
|
||||||
const response = await request(app)
|
data: {
|
||||||
.post('/graphql')
|
getExecutions: {
|
||||||
.set('Authorization', token)
|
edges: [
|
||||||
.send({ query })
|
expectedResponseForExecutionThree,
|
||||||
.expect(200);
|
expectedResponseForExecutionTwo,
|
||||||
|
expectedResponseForExecutionOne,
|
||||||
const expectedResponsePayload = {
|
],
|
||||||
data: {
|
pageInfo: { currentPage: 1, totalPages: 1 },
|
||||||
getExecutions: {
|
|
||||||
edges: [
|
|
||||||
expectedResponseForExecutionThree,
|
|
||||||
expectedResponseForExecutionTwo,
|
|
||||||
expectedResponseForExecutionOne,
|
|
||||||
],
|
|
||||||
pageInfo: { currentPage: 1, totalPages: 1 },
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
},
|
||||||
|
};
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedResponsePayload);
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and with filters', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await createPermission({
|
||||||
|
action: 'read',
|
||||||
|
subject: 'Execution',
|
||||||
|
roleId: role.id,
|
||||||
|
conditions: [],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('and with filters', () => {
|
it('should return executions data for the specified flow', async () => {
|
||||||
beforeEach(async () => {
|
const query = `
|
||||||
await createPermission({
|
|
||||||
action: 'read',
|
|
||||||
subject: 'Execution',
|
|
||||||
roleId: role.id,
|
|
||||||
conditions: [],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return executions data for the specified flow', async () => {
|
|
||||||
const query = `
|
|
||||||
query {
|
query {
|
||||||
getExecutions(limit: 10, offset: 0, filters: { flowId: "${flowOne.id}" }) {
|
getExecutions(limit: 10, offset: 0, filters: { flowId: "${flowOne.id}" }) {
|
||||||
pageInfo {
|
pageInfo {
|
||||||
@@ -368,26 +352,26 @@ describe('graphQL getExecutions query', () => {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post('/graphql')
|
.post('/graphql')
|
||||||
.set('Authorization', token)
|
.set('Authorization', token)
|
||||||
.send({ query })
|
.send({ query })
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
const expectedResponsePayload = {
|
const expectedResponsePayload = {
|
||||||
data: {
|
data: {
|
||||||
getExecutions: {
|
getExecutions: {
|
||||||
edges: [expectedResponseForExecutionOne],
|
edges: [expectedResponseForExecutionOne],
|
||||||
pageInfo: { currentPage: 1, totalPages: 1 },
|
pageInfo: { currentPage: 1, totalPages: 1 },
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
},
|
||||||
|
};
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedResponsePayload);
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return only executions data with success status', async () => {
|
it('should return only executions data with success status', async () => {
|
||||||
const query = `
|
const query = `
|
||||||
query {
|
query {
|
||||||
getExecutions(limit: 10, offset: 0, filters: { status: "success" }) {
|
getExecutions(limit: 10, offset: 0, filters: { status: "success" }) {
|
||||||
pageInfo {
|
pageInfo {
|
||||||
@@ -415,30 +399,30 @@ describe('graphQL getExecutions query', () => {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post('/graphql')
|
.post('/graphql')
|
||||||
.set('Authorization', token)
|
.set('Authorization', token)
|
||||||
.send({ query })
|
.send({ query })
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
const expectedResponsePayload = {
|
const expectedResponsePayload = {
|
||||||
data: {
|
data: {
|
||||||
getExecutions: {
|
getExecutions: {
|
||||||
edges: [expectedResponseForExecutionOne],
|
edges: [expectedResponseForExecutionOne],
|
||||||
pageInfo: { currentPage: 1, totalPages: 1 },
|
pageInfo: { currentPage: 1, totalPages: 1 },
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
},
|
||||||
|
};
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedResponsePayload);
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return only executions data within date range', async () => {
|
it('should return only executions data within date range', async () => {
|
||||||
const createdAtFrom = executionOne.createdAt.getTime().toString();
|
const createdAtFrom = executionOne.createdAt.getTime().toString();
|
||||||
|
|
||||||
const createdAtTo = executionOne.createdAt.getTime().toString();
|
const createdAtTo = executionOne.createdAt.getTime().toString();
|
||||||
|
|
||||||
const query = `
|
const query = `
|
||||||
query {
|
query {
|
||||||
getExecutions(limit: 10, offset: 0, filters: { createdAt: { from: "${createdAtFrom}", to: "${createdAtTo}" }}) {
|
getExecutions(limit: 10, offset: 0, filters: { createdAt: { from: "${createdAtFrom}", to: "${createdAtTo}" }}) {
|
||||||
pageInfo {
|
pageInfo {
|
||||||
@@ -466,23 +450,22 @@ describe('graphQL getExecutions query', () => {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post('/graphql')
|
.post('/graphql')
|
||||||
.set('Authorization', token)
|
.set('Authorization', token)
|
||||||
.send({ query })
|
.send({ query })
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
const expectedResponsePayload = {
|
const expectedResponsePayload = {
|
||||||
data: {
|
data: {
|
||||||
getExecutions: {
|
getExecutions: {
|
||||||
edges: [expectedResponseForExecutionOne],
|
edges: [expectedResponseForExecutionOne],
|
||||||
pageInfo: { currentPage: 1, totalPages: 1 },
|
pageInfo: { currentPage: 1, totalPages: 1 },
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
},
|
||||||
|
};
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedResponsePayload);
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -40,222 +40,200 @@ describe('graphQL getFlow query', () => {
|
|||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('with unauthenticated user', () => {
|
describe('and without permissions', () => {
|
||||||
it('should throw not authorized error', async () => {
|
it('should throw not authorized error', async () => {
|
||||||
const invalidToken = 'invalid-token';
|
const userWithoutPermissions = await createUser();
|
||||||
|
const token = createAuthTokenByUserId(userWithoutPermissions.id);
|
||||||
const flow = await createFlow();
|
const flow = await createFlow();
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post('/graphql')
|
.post('/graphql')
|
||||||
.set('Authorization', invalidToken)
|
.set('Authorization', token)
|
||||||
.send({ query: query(flow.id) })
|
.send({ query: query(flow.id) })
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
expect(response.body.errors).toBeDefined();
|
||||||
expect(response.body.errors[0].message).toEqual('Not Authorised!');
|
expect(response.body.errors[0].message).toEqual('Not authorized!');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with authenticated user', () => {
|
describe('and with correct permission', () => {
|
||||||
describe('and without permissions', () => {
|
let currentUser, currentUserRole, currentUserFlow;
|
||||||
it('should throw not authorized error', async () => {
|
|
||||||
const userWithoutPermissions = await createUser();
|
beforeEach(async () => {
|
||||||
const token = createAuthTokenByUserId(userWithoutPermissions.id);
|
currentUserRole = await createRole();
|
||||||
const flow = await createFlow();
|
currentUser = await createUser({ roleId: currentUserRole.id });
|
||||||
|
currentUserFlow = await createFlow({ userId: currentUser.id });
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and with isCreator condition', () => {
|
||||||
|
it('should return executions data of the current user', async () => {
|
||||||
|
await createPermission({
|
||||||
|
action: 'read',
|
||||||
|
subject: 'Flow',
|
||||||
|
roleId: currentUserRole.id,
|
||||||
|
conditions: ['isCreator'],
|
||||||
|
});
|
||||||
|
|
||||||
|
const triggerStep = await createStep({
|
||||||
|
flowId: currentUserFlow.id,
|
||||||
|
type: 'trigger',
|
||||||
|
key: 'catchRawWebhook',
|
||||||
|
webhookPath: `/webhooks/flows/${currentUserFlow.id}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
const actionConnection = await createConnection({
|
||||||
|
userId: currentUser.id,
|
||||||
|
formattedData: {
|
||||||
|
screenName: 'Test',
|
||||||
|
authenticationKey: 'test key',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const actionStep = await createStep({
|
||||||
|
flowId: currentUserFlow.id,
|
||||||
|
type: 'action',
|
||||||
|
connectionId: actionConnection.id,
|
||||||
|
key: 'translateText',
|
||||||
|
});
|
||||||
|
|
||||||
|
const token = createAuthTokenByUserId(currentUser.id);
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post('/graphql')
|
.post('/graphql')
|
||||||
.set('Authorization', token)
|
.set('Authorization', token)
|
||||||
.send({ query: query(flow.id) })
|
.send({ query: query(currentUserFlow.id) })
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
const expectedResponsePayload = {
|
||||||
expect(response.body.errors[0].message).toEqual('Not authorized!');
|
data: {
|
||||||
|
getFlow: {
|
||||||
|
active: currentUserFlow.active,
|
||||||
|
id: currentUserFlow.id,
|
||||||
|
name: currentUserFlow.name,
|
||||||
|
status: 'draft',
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
appKey: triggerStep.appKey,
|
||||||
|
connection: null,
|
||||||
|
iconUrl: `${appConfig.baseUrl}/apps/${triggerStep.appKey}/assets/favicon.svg`,
|
||||||
|
id: triggerStep.id,
|
||||||
|
key: 'catchRawWebhook',
|
||||||
|
parameters: {},
|
||||||
|
position: 1,
|
||||||
|
status: triggerStep.status,
|
||||||
|
type: 'trigger',
|
||||||
|
webhookUrl: `${appConfig.baseUrl}/webhooks/flows/${currentUserFlow.id}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
appKey: actionStep.appKey,
|
||||||
|
connection: {
|
||||||
|
createdAt: actionConnection.createdAt.getTime().toString(),
|
||||||
|
id: actionConnection.id,
|
||||||
|
verified: actionConnection.verified,
|
||||||
|
},
|
||||||
|
iconUrl: `${appConfig.baseUrl}/apps/${actionStep.appKey}/assets/favicon.svg`,
|
||||||
|
id: actionStep.id,
|
||||||
|
key: 'translateText',
|
||||||
|
parameters: {},
|
||||||
|
position: 1,
|
||||||
|
status: actionStep.status,
|
||||||
|
type: 'action',
|
||||||
|
webhookUrl: 'http://localhost:3000/null',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('and with correct permission', () => {
|
describe('and without isCreator condition', () => {
|
||||||
let currentUser, currentUserRole, currentUserFlow;
|
it('should return executions data of all users', async () => {
|
||||||
|
await createPermission({
|
||||||
beforeEach(async () => {
|
action: 'read',
|
||||||
currentUserRole = await createRole();
|
subject: 'Flow',
|
||||||
currentUser = await createUser({ roleId: currentUserRole.id });
|
roleId: currentUserRole.id,
|
||||||
currentUserFlow = await createFlow({ userId: currentUser.id });
|
conditions: [],
|
||||||
});
|
|
||||||
|
|
||||||
describe('and with isCreator condition', () => {
|
|
||||||
it('should return executions data of the current user', async () => {
|
|
||||||
await createPermission({
|
|
||||||
action: 'read',
|
|
||||||
subject: 'Flow',
|
|
||||||
roleId: currentUserRole.id,
|
|
||||||
conditions: ['isCreator'],
|
|
||||||
});
|
|
||||||
|
|
||||||
const triggerStep = await createStep({
|
|
||||||
flowId: currentUserFlow.id,
|
|
||||||
type: 'trigger',
|
|
||||||
key: 'catchRawWebhook',
|
|
||||||
webhookPath: `/webhooks/flows/${currentUserFlow.id}`,
|
|
||||||
});
|
|
||||||
|
|
||||||
const actionConnection = await createConnection({
|
|
||||||
userId: currentUser.id,
|
|
||||||
formattedData: {
|
|
||||||
screenName: 'Test',
|
|
||||||
authenticationKey: 'test key',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const actionStep = await createStep({
|
|
||||||
flowId: currentUserFlow.id,
|
|
||||||
type: 'action',
|
|
||||||
connectionId: actionConnection.id,
|
|
||||||
key: 'translateText',
|
|
||||||
});
|
|
||||||
|
|
||||||
const token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
|
|
||||||
const response = await request(app)
|
|
||||||
.post('/graphql')
|
|
||||||
.set('Authorization', token)
|
|
||||||
.send({ query: query(currentUserFlow.id) })
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedResponsePayload = {
|
|
||||||
data: {
|
|
||||||
getFlow: {
|
|
||||||
active: currentUserFlow.active,
|
|
||||||
id: currentUserFlow.id,
|
|
||||||
name: currentUserFlow.name,
|
|
||||||
status: 'draft',
|
|
||||||
steps: [
|
|
||||||
{
|
|
||||||
appKey: triggerStep.appKey,
|
|
||||||
connection: null,
|
|
||||||
iconUrl: `${appConfig.baseUrl}/apps/${triggerStep.appKey}/assets/favicon.svg`,
|
|
||||||
id: triggerStep.id,
|
|
||||||
key: 'catchRawWebhook',
|
|
||||||
parameters: {},
|
|
||||||
position: 1,
|
|
||||||
status: triggerStep.status,
|
|
||||||
type: 'trigger',
|
|
||||||
webhookUrl: `${appConfig.baseUrl}/webhooks/flows/${currentUserFlow.id}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
appKey: actionStep.appKey,
|
|
||||||
connection: {
|
|
||||||
createdAt: actionConnection.createdAt
|
|
||||||
.getTime()
|
|
||||||
.toString(),
|
|
||||||
id: actionConnection.id,
|
|
||||||
verified: actionConnection.verified,
|
|
||||||
},
|
|
||||||
iconUrl: `${appConfig.baseUrl}/apps/${actionStep.appKey}/assets/favicon.svg`,
|
|
||||||
id: actionStep.id,
|
|
||||||
key: 'translateText',
|
|
||||||
parameters: {},
|
|
||||||
position: 1,
|
|
||||||
status: actionStep.status,
|
|
||||||
type: 'action',
|
|
||||||
webhookUrl: 'http://localhost:3000/null',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedResponsePayload);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('and without isCreator condition', () => {
|
const anotherUser = await createUser();
|
||||||
it('should return executions data of all users', async () => {
|
const anotherUserFlow = await createFlow({ userId: anotherUser.id });
|
||||||
await createPermission({
|
|
||||||
action: 'read',
|
|
||||||
subject: 'Flow',
|
|
||||||
roleId: currentUserRole.id,
|
|
||||||
conditions: [],
|
|
||||||
});
|
|
||||||
|
|
||||||
const anotherUser = await createUser();
|
const triggerStep = await createStep({
|
||||||
const anotherUserFlow = await createFlow({ userId: anotherUser.id });
|
flowId: anotherUserFlow.id,
|
||||||
|
type: 'trigger',
|
||||||
const triggerStep = await createStep({
|
key: 'catchRawWebhook',
|
||||||
flowId: anotherUserFlow.id,
|
webhookPath: `/webhooks/flows/${anotherUserFlow.id}`,
|
||||||
type: 'trigger',
|
|
||||||
key: 'catchRawWebhook',
|
|
||||||
webhookPath: `/webhooks/flows/${anotherUserFlow.id}`,
|
|
||||||
});
|
|
||||||
|
|
||||||
const actionConnection = await createConnection({
|
|
||||||
userId: anotherUser.id,
|
|
||||||
formattedData: {
|
|
||||||
screenName: 'Test',
|
|
||||||
authenticationKey: 'test key',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const actionStep = await createStep({
|
|
||||||
flowId: anotherUserFlow.id,
|
|
||||||
type: 'action',
|
|
||||||
connectionId: actionConnection.id,
|
|
||||||
key: 'translateText',
|
|
||||||
});
|
|
||||||
|
|
||||||
const token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
|
|
||||||
const response = await request(app)
|
|
||||||
.post('/graphql')
|
|
||||||
.set('Authorization', token)
|
|
||||||
.send({ query: query(anotherUserFlow.id) })
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedResponsePayload = {
|
|
||||||
data: {
|
|
||||||
getFlow: {
|
|
||||||
active: anotherUserFlow.active,
|
|
||||||
id: anotherUserFlow.id,
|
|
||||||
name: anotherUserFlow.name,
|
|
||||||
status: 'draft',
|
|
||||||
steps: [
|
|
||||||
{
|
|
||||||
appKey: triggerStep.appKey,
|
|
||||||
connection: null,
|
|
||||||
iconUrl: `${appConfig.baseUrl}/apps/${triggerStep.appKey}/assets/favicon.svg`,
|
|
||||||
id: triggerStep.id,
|
|
||||||
key: 'catchRawWebhook',
|
|
||||||
parameters: {},
|
|
||||||
position: 1,
|
|
||||||
status: triggerStep.status,
|
|
||||||
type: 'trigger',
|
|
||||||
webhookUrl: `${appConfig.baseUrl}/webhooks/flows/${anotherUserFlow.id}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
appKey: actionStep.appKey,
|
|
||||||
connection: {
|
|
||||||
createdAt: actionConnection.createdAt
|
|
||||||
.getTime()
|
|
||||||
.toString(),
|
|
||||||
id: actionConnection.id,
|
|
||||||
verified: actionConnection.verified,
|
|
||||||
},
|
|
||||||
iconUrl: `${appConfig.baseUrl}/apps/${actionStep.appKey}/assets/favicon.svg`,
|
|
||||||
id: actionStep.id,
|
|
||||||
key: 'translateText',
|
|
||||||
parameters: {},
|
|
||||||
position: 1,
|
|
||||||
status: actionStep.status,
|
|
||||||
type: 'action',
|
|
||||||
webhookUrl: 'http://localhost:3000/null',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedResponsePayload);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const actionConnection = await createConnection({
|
||||||
|
userId: anotherUser.id,
|
||||||
|
formattedData: {
|
||||||
|
screenName: 'Test',
|
||||||
|
authenticationKey: 'test key',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const actionStep = await createStep({
|
||||||
|
flowId: anotherUserFlow.id,
|
||||||
|
type: 'action',
|
||||||
|
connectionId: actionConnection.id,
|
||||||
|
key: 'translateText',
|
||||||
|
});
|
||||||
|
|
||||||
|
const token = createAuthTokenByUserId(currentUser.id);
|
||||||
|
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', token)
|
||||||
|
.send({ query: query(anotherUserFlow.id) })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedResponsePayload = {
|
||||||
|
data: {
|
||||||
|
getFlow: {
|
||||||
|
active: anotherUserFlow.active,
|
||||||
|
id: anotherUserFlow.id,
|
||||||
|
name: anotherUserFlow.name,
|
||||||
|
status: 'draft',
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
appKey: triggerStep.appKey,
|
||||||
|
connection: null,
|
||||||
|
iconUrl: `${appConfig.baseUrl}/apps/${triggerStep.appKey}/assets/favicon.svg`,
|
||||||
|
id: triggerStep.id,
|
||||||
|
key: 'catchRawWebhook',
|
||||||
|
parameters: {},
|
||||||
|
position: 1,
|
||||||
|
status: triggerStep.status,
|
||||||
|
type: 'trigger',
|
||||||
|
webhookUrl: `${appConfig.baseUrl}/webhooks/flows/${anotherUserFlow.id}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
appKey: actionStep.appKey,
|
||||||
|
connection: {
|
||||||
|
createdAt: actionConnection.createdAt.getTime().toString(),
|
||||||
|
id: actionConnection.id,
|
||||||
|
verified: actionConnection.verified,
|
||||||
|
},
|
||||||
|
iconUrl: `${appConfig.baseUrl}/apps/${actionStep.appKey}/assets/favicon.svg`,
|
||||||
|
id: actionStep.id,
|
||||||
|
key: 'translateText',
|
||||||
|
parameters: {},
|
||||||
|
position: 1,
|
||||||
|
status: actionStep.status,
|
||||||
|
type: 'action',
|
||||||
|
webhookUrl: 'http://localhost:3000/null',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -17,7 +17,6 @@ describe('graphQL getRole query', () => {
|
|||||||
userWithoutPermissions,
|
userWithoutPermissions,
|
||||||
tokenWithPermissions,
|
tokenWithPermissions,
|
||||||
tokenWithoutPermissions,
|
tokenWithoutPermissions,
|
||||||
invalidToken,
|
|
||||||
permissionOne,
|
permissionOne,
|
||||||
permissionTwo;
|
permissionTwo;
|
||||||
|
|
||||||
@@ -74,108 +73,91 @@ describe('graphQL getRole query', () => {
|
|||||||
tokenWithoutPermissions = createAuthTokenByUserId(
|
tokenWithoutPermissions = createAuthTokenByUserId(
|
||||||
userWithoutPermissions.id
|
userWithoutPermissions.id
|
||||||
);
|
);
|
||||||
|
|
||||||
invalidToken = 'invalid-token';
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with unauthenticated user', () => {
|
describe('and with valid license', () => {
|
||||||
it('should throw not authorized error', async () => {
|
beforeEach(async () => {
|
||||||
const response = await request(app)
|
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
||||||
.post('/graphql')
|
|
||||||
.set('Authorization', invalidToken)
|
|
||||||
.send({ query: queryWithValidRole })
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
|
||||||
expect(response.body.errors[0].message).toEqual('Not Authorised!');
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('with authenticated user', () => {
|
describe('and without permissions', () => {
|
||||||
describe('and with valid license', () => {
|
it('should throw not authorized error', async () => {
|
||||||
beforeEach(async () => {
|
const response = await request(app)
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
.post('/graphql')
|
||||||
|
.set('Authorization', tokenWithoutPermissions)
|
||||||
|
.send({ query: queryWithValidRole })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
expect(response.body.errors).toBeDefined();
|
||||||
|
expect(response.body.errors[0].message).toEqual('Not authorized!');
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('and without permissions', () => {
|
describe('and correct permissions', () => {
|
||||||
it('should throw not authorized error', async () => {
|
it('should return role data for a valid role id', async () => {
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post('/graphql')
|
.post('/graphql')
|
||||||
.set('Authorization', tokenWithoutPermissions)
|
.set('Authorization', tokenWithPermissions)
|
||||||
.send({ query: queryWithValidRole })
|
.send({ query: queryWithValidRole })
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
const expectedResponsePayload = {
|
||||||
expect(response.body.errors[0].message).toEqual('Not authorized!');
|
data: {
|
||||||
});
|
getRole: {
|
||||||
});
|
description: validRole.description,
|
||||||
|
id: validRole.id,
|
||||||
describe('and correct permissions', () => {
|
isAdmin: validRole.key === 'admin',
|
||||||
it('should return role data for a valid role id', async () => {
|
key: validRole.key,
|
||||||
const response = await request(app)
|
name: validRole.name,
|
||||||
.post('/graphql')
|
permissions: [
|
||||||
.set('Authorization', tokenWithPermissions)
|
{
|
||||||
.send({ query: queryWithValidRole })
|
action: permissionOne.action,
|
||||||
.expect(200);
|
conditions: permissionOne.conditions,
|
||||||
|
id: permissionOne.id,
|
||||||
const expectedResponsePayload = {
|
subject: permissionOne.subject,
|
||||||
data: {
|
},
|
||||||
getRole: {
|
{
|
||||||
description: validRole.description,
|
action: permissionTwo.action,
|
||||||
id: validRole.id,
|
conditions: permissionTwo.conditions,
|
||||||
isAdmin: validRole.key === 'admin',
|
id: permissionTwo.id,
|
||||||
key: validRole.key,
|
subject: permissionTwo.subject,
|
||||||
name: validRole.name,
|
},
|
||||||
permissions: [
|
],
|
||||||
{
|
|
||||||
action: permissionOne.action,
|
|
||||||
conditions: permissionOne.conditions,
|
|
||||||
id: permissionOne.id,
|
|
||||||
subject: permissionOne.subject,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
action: permissionTwo.action,
|
|
||||||
conditions: permissionTwo.conditions,
|
|
||||||
id: permissionTwo.id,
|
|
||||||
subject: permissionTwo.subject,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
},
|
||||||
|
};
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedResponsePayload);
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return not found for invalid role id', async () => {
|
it('should return not found for invalid role id', async () => {
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post('/graphql')
|
.post('/graphql')
|
||||||
.set('Authorization', tokenWithPermissions)
|
.set('Authorization', tokenWithPermissions)
|
||||||
.send({ query: queryWithInvalidRole })
|
.send({ query: queryWithInvalidRole })
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
expect(response.body.errors).toBeDefined();
|
||||||
expect(response.body.errors[0].message).toEqual('NotFoundError');
|
expect(response.body.errors[0].message).toEqual('NotFoundError');
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('and without valid license', () => {
|
describe('and without valid license', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(false);
|
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('and correct permissions', () => {
|
describe('and correct permissions', () => {
|
||||||
it('should throw not authorized error', async () => {
|
it('should throw not authorized error', async () => {
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post('/graphql')
|
.post('/graphql')
|
||||||
.set('Authorization', tokenWithPermissions)
|
.set('Authorization', tokenWithPermissions)
|
||||||
.send({ query: queryWithInvalidRole })
|
.send({ query: queryWithInvalidRole })
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
expect(response.body.errors).toBeDefined();
|
||||||
expect(response.body.errors[0].message).toEqual('Not authorized!');
|
expect(response.body.errors[0].message).toEqual('Not authorized!');
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -15,8 +15,7 @@ describe('graphQL getRoles query', () => {
|
|||||||
userWithPermissions,
|
userWithPermissions,
|
||||||
userWithoutPermissions,
|
userWithoutPermissions,
|
||||||
tokenWithPermissions,
|
tokenWithPermissions,
|
||||||
tokenWithoutPermissions,
|
tokenWithoutPermissions;
|
||||||
invalidToken;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
currentUserRole = await createRole({ name: 'Current user role' });
|
currentUserRole = await createRole({ name: 'Current user role' });
|
||||||
@@ -53,99 +52,82 @@ describe('graphQL getRoles query', () => {
|
|||||||
tokenWithoutPermissions = createAuthTokenByUserId(
|
tokenWithoutPermissions = createAuthTokenByUserId(
|
||||||
userWithoutPermissions.id
|
userWithoutPermissions.id
|
||||||
);
|
);
|
||||||
|
|
||||||
invalidToken = 'invalid-token';
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with unauthenticated user', () => {
|
describe('and with valid license', () => {
|
||||||
it('should throw not authorized error', async () => {
|
beforeEach(async () => {
|
||||||
const response = await request(app)
|
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
||||||
.post('/graphql')
|
|
||||||
.set('Authorization', invalidToken)
|
|
||||||
.send({ query })
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
|
||||||
expect(response.body.errors[0].message).toEqual('Not Authorised!');
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('with authenticated user', () => {
|
describe('and without permissions', () => {
|
||||||
describe('and with valid license', () => {
|
it('should throw not authorized error', async () => {
|
||||||
beforeEach(async () => {
|
const response = await request(app)
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
.post('/graphql')
|
||||||
});
|
.set('Authorization', tokenWithoutPermissions)
|
||||||
|
.send({ query })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
describe('and without permissions', () => {
|
expect(response.body.errors).toBeDefined();
|
||||||
it('should throw not authorized error', async () => {
|
expect(response.body.errors[0].message).toEqual('Not authorized!');
|
||||||
const response = await request(app)
|
|
||||||
.post('/graphql')
|
|
||||||
.set('Authorization', tokenWithoutPermissions)
|
|
||||||
.send({ query })
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
|
||||||
expect(response.body.errors[0].message).toEqual('Not authorized!');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('and correct permissions', () => {
|
|
||||||
it('should return roles data', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.post('/graphql')
|
|
||||||
.set('Authorization', tokenWithPermissions)
|
|
||||||
.send({ query })
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedResponsePayload = {
|
|
||||||
data: {
|
|
||||||
getRoles: [
|
|
||||||
{
|
|
||||||
description: currentUserRole.description,
|
|
||||||
id: currentUserRole.id,
|
|
||||||
isAdmin: currentUserRole.key === 'admin',
|
|
||||||
key: currentUserRole.key,
|
|
||||||
name: currentUserRole.name,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
description: roleOne.description,
|
|
||||||
id: roleOne.id,
|
|
||||||
isAdmin: roleOne.key === 'admin',
|
|
||||||
key: roleOne.key,
|
|
||||||
name: roleOne.name,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
description: roleSecond.description,
|
|
||||||
id: roleSecond.id,
|
|
||||||
isAdmin: roleSecond.key === 'admin',
|
|
||||||
key: roleSecond.key,
|
|
||||||
name: roleSecond.name,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedResponsePayload);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('and without valid license', () => {
|
describe('and correct permissions', () => {
|
||||||
beforeEach(async () => {
|
it('should return roles data', async () => {
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(false);
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', tokenWithPermissions)
|
||||||
|
.send({ query })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedResponsePayload = {
|
||||||
|
data: {
|
||||||
|
getRoles: [
|
||||||
|
{
|
||||||
|
description: currentUserRole.description,
|
||||||
|
id: currentUserRole.id,
|
||||||
|
isAdmin: currentUserRole.key === 'admin',
|
||||||
|
key: currentUserRole.key,
|
||||||
|
name: currentUserRole.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: roleOne.description,
|
||||||
|
id: roleOne.id,
|
||||||
|
isAdmin: roleOne.key === 'admin',
|
||||||
|
key: roleOne.key,
|
||||||
|
name: roleOne.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: roleSecond.description,
|
||||||
|
id: roleSecond.id,
|
||||||
|
isAdmin: roleSecond.key === 'admin',
|
||||||
|
key: roleSecond.key,
|
||||||
|
name: roleSecond.name,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('and correct permissions', () => {
|
describe('and without valid license', () => {
|
||||||
it('should throw not authorized error', async () => {
|
beforeEach(async () => {
|
||||||
const response = await request(app)
|
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(false);
|
||||||
.post('/graphql')
|
});
|
||||||
.set('Authorization', tokenWithPermissions)
|
|
||||||
.send({ query })
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
describe('and correct permissions', () => {
|
||||||
expect(response.body.errors[0].message).toEqual('Not authorized!');
|
it('should throw not authorized error', async () => {
|
||||||
});
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', tokenWithPermissions)
|
||||||
|
.send({ query })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
expect(response.body.errors).toBeDefined();
|
||||||
|
expect(response.body.errors[0].message).toEqual('Not authorized!');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -16,34 +16,46 @@ describe('graphQL getTrialStatus query', () => {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const invalidToken = 'invalid-token';
|
let user, userToken;
|
||||||
|
|
||||||
describe('with unauthenticated user', () => {
|
beforeEach(async () => {
|
||||||
it('should throw not authorized error', async () => {
|
const trialExpiryDate = DateTime.now().plus({ days: 30 }).toISODate();
|
||||||
|
|
||||||
|
user = await createUser({ trialExpiryDate });
|
||||||
|
userToken = createAuthTokenByUserId(user.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and with cloud flag disabled', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return null', async () => {
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post('/graphql')
|
.post('/graphql')
|
||||||
.set('Authorization', invalidToken)
|
.set('Authorization', userToken)
|
||||||
.send({ query })
|
.send({ query })
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
const expectedResponsePayload = {
|
||||||
expect(response.body.errors[0].message).toEqual('Not Authorised!');
|
data: { getTrialStatus: null },
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with authenticated user', () => {
|
describe('and with cloud flag enabled', () => {
|
||||||
let user, userToken;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const trialExpiryDate = DateTime.now().plus({ days: 30 }).toISODate();
|
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(true);
|
||||||
|
|
||||||
user = await createUser({ trialExpiryDate });
|
|
||||||
userToken = createAuthTokenByUserId(user.id);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('and with cloud flag disabled', () => {
|
describe('and not in trial and has active subscription', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(false);
|
vi.spyOn(User.prototype, 'inTrial').mockResolvedValue(false);
|
||||||
|
vi.spyOn(User.prototype, 'hasActiveSubscription').mockResolvedValue(
|
||||||
|
true
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null', async () => {
|
it('should return null', async () => {
|
||||||
@@ -61,56 +73,27 @@ describe('graphQL getTrialStatus query', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('and with cloud flag enabled', () => {
|
describe('and in trial period', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(true);
|
vi.spyOn(User.prototype, 'inTrial').mockResolvedValue(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('and not in trial and has active subscription', () => {
|
it('should return null', async () => {
|
||||||
beforeEach(async () => {
|
const response = await request(app)
|
||||||
vi.spyOn(User.prototype, 'inTrial').mockResolvedValue(false);
|
.post('/graphql')
|
||||||
vi.spyOn(User.prototype, 'hasActiveSubscription').mockResolvedValue(
|
.set('Authorization', userToken)
|
||||||
true
|
.send({ query })
|
||||||
);
|
.expect(200);
|
||||||
});
|
|
||||||
|
|
||||||
it('should return null', async () => {
|
const expectedResponsePayload = {
|
||||||
const response = await request(app)
|
data: {
|
||||||
.post('/graphql')
|
getTrialStatus: {
|
||||||
.set('Authorization', userToken)
|
expireAt: new Date(user.trialExpiryDate).getTime().toString(),
|
||||||
.send({ query })
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedResponsePayload = {
|
|
||||||
data: { getTrialStatus: null },
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedResponsePayload);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('and in trial period', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
vi.spyOn(User.prototype, 'inTrial').mockResolvedValue(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return null', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.post('/graphql')
|
|
||||||
.set('Authorization', userToken)
|
|
||||||
.send({ query })
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedResponsePayload = {
|
|
||||||
data: {
|
|
||||||
getTrialStatus: {
|
|
||||||
expireAt: new Date(user.trialExpiryDate).getTime().toString(),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
},
|
||||||
|
};
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedResponsePayload);
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -8,37 +8,12 @@ import { createPermission } from '../../../test/factories/permission';
|
|||||||
import { createUser } from '../../../test/factories/user';
|
import { createUser } from '../../../test/factories/user';
|
||||||
|
|
||||||
describe('graphQL getUser query', () => {
|
describe('graphQL getUser query', () => {
|
||||||
describe('with unauthenticated user', () => {
|
describe('and without permissions', () => {
|
||||||
it('should throw not authorized error', async () => {
|
it('should throw not authorized error', async () => {
|
||||||
const invalidUserId = '123123123';
|
const userWithoutPermissions = await createUser();
|
||||||
|
const anotherUser = await createUser();
|
||||||
|
|
||||||
const query = `
|
const query = `
|
||||||
query {
|
|
||||||
getUser(id: "${invalidUserId}") {
|
|
||||||
id
|
|
||||||
email
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const response = await request(app)
|
|
||||||
.post('/graphql')
|
|
||||||
.set('Authorization', 'invalid-token')
|
|
||||||
.send({ query })
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
|
||||||
expect(response.body.errors[0].message).toEqual('Not Authorised!');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('with authenticated user', () => {
|
|
||||||
describe('and without permissions', () => {
|
|
||||||
it('should throw not authorized error', async () => {
|
|
||||||
const userWithoutPermissions = await createUser();
|
|
||||||
const anotherUser = await createUser();
|
|
||||||
|
|
||||||
const query = `
|
|
||||||
query {
|
query {
|
||||||
getUser(id: "${anotherUser.id}") {
|
getUser(id: "${anotherUser.id}") {
|
||||||
id
|
id
|
||||||
@@ -47,50 +22,48 @@ describe('graphQL getUser query', () => {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const token = createAuthTokenByUserId(userWithoutPermissions.id);
|
const token = createAuthTokenByUserId(userWithoutPermissions.id);
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post('/graphql')
|
.post('/graphql')
|
||||||
.set('Authorization', token)
|
.set('Authorization', token)
|
||||||
.send({ query })
|
.send({ query })
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
expect(response.body.errors).toBeDefined();
|
||||||
expect(response.body.errors[0].message).toEqual('Not authorized!');
|
expect(response.body.errors[0].message).toEqual('Not authorized!');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and correct permissions', () => {
|
||||||
|
let role, currentUser, anotherUser, token, requestObject;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
role = await createRole({
|
||||||
|
key: 'sample',
|
||||||
|
name: 'sample',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await createPermission({
|
||||||
|
action: 'read',
|
||||||
|
subject: 'User',
|
||||||
|
roleId: role.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
currentUser = await createUser({
|
||||||
|
roleId: role.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
anotherUser = await createUser({
|
||||||
|
roleId: role.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
token = createAuthTokenByUserId(currentUser.id);
|
||||||
|
requestObject = request(app).post('/graphql').set('Authorization', token);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('and correct permissions', () => {
|
it('should return user data for a valid user id', async () => {
|
||||||
let role, currentUser, anotherUser, token, requestObject;
|
const query = `
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
role = await createRole({
|
|
||||||
key: 'sample',
|
|
||||||
name: 'sample',
|
|
||||||
});
|
|
||||||
|
|
||||||
await createPermission({
|
|
||||||
action: 'read',
|
|
||||||
subject: 'User',
|
|
||||||
roleId: role.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
currentUser = await createUser({
|
|
||||||
roleId: role.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
anotherUser = await createUser({
|
|
||||||
roleId: role.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
requestObject = request(app)
|
|
||||||
.post('/graphql')
|
|
||||||
.set('Authorization', token);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return user data for a valid user id', async () => {
|
|
||||||
const query = `
|
|
||||||
query {
|
query {
|
||||||
getUser(id: "${anotherUser.id}") {
|
getUser(id: "${anotherUser.id}") {
|
||||||
id
|
id
|
||||||
@@ -107,26 +80,26 @@ describe('graphQL getUser query', () => {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const response = await requestObject.send({ query }).expect(200);
|
const response = await requestObject.send({ query }).expect(200);
|
||||||
|
|
||||||
const expectedResponsePayload = {
|
const expectedResponsePayload = {
|
||||||
data: {
|
data: {
|
||||||
getUser: {
|
getUser: {
|
||||||
createdAt: anotherUser.createdAt.getTime().toString(),
|
createdAt: anotherUser.createdAt.getTime().toString(),
|
||||||
email: anotherUser.email,
|
email: anotherUser.email,
|
||||||
fullName: anotherUser.fullName,
|
fullName: anotherUser.fullName,
|
||||||
id: anotherUser.id,
|
id: anotherUser.id,
|
||||||
role: { id: role.id, name: role.name },
|
role: { id: role.id, name: role.name },
|
||||||
updatedAt: anotherUser.updatedAt.getTime().toString(),
|
updatedAt: anotherUser.updatedAt.getTime().toString(),
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
},
|
||||||
|
};
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedResponsePayload);
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not return user password for a valid user id', async () => {
|
it('should not return user password for a valid user id', async () => {
|
||||||
const query = `
|
const query = `
|
||||||
query {
|
query {
|
||||||
getUser(id: "${anotherUser.id}") {
|
getUser(id: "${anotherUser.id}") {
|
||||||
id
|
id
|
||||||
@@ -136,18 +109,18 @@ describe('graphQL getUser query', () => {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const response = await requestObject.send({ query }).expect(400);
|
const response = await requestObject.send({ query }).expect(400);
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
expect(response.body.errors).toBeDefined();
|
||||||
expect(response.body.errors[0].message).toEqual(
|
expect(response.body.errors[0].message).toEqual(
|
||||||
'Cannot query field "password" on type "User".'
|
'Cannot query field "password" on type "User".'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return not found for invalid user id', async () => {
|
it('should return not found for invalid user id', async () => {
|
||||||
const invalidUserId = Crypto.randomUUID();
|
const invalidUserId = Crypto.randomUUID();
|
||||||
|
|
||||||
const query = `
|
const query = `
|
||||||
query {
|
query {
|
||||||
getUser(id: "${invalidUserId}") {
|
getUser(id: "${invalidUserId}") {
|
||||||
id
|
id
|
||||||
@@ -164,11 +137,10 @@ describe('graphQL getUser query', () => {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const response = await requestObject.send({ query }).expect(200);
|
const response = await requestObject.send({ query }).expect(200);
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
expect(response.body.errors).toBeDefined();
|
||||||
expect(response.body.errors[0].message).toEqual('NotFoundError');
|
expect(response.body.errors[0].message).toEqual('NotFoundError');
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -30,111 +30,95 @@ describe('graphQL getUsers query', () => {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
describe('with unauthenticated user', () => {
|
describe('and without permissions', () => {
|
||||||
it('should throw not authorized error', async () => {
|
it('should throw not authorized error', async () => {
|
||||||
|
const userWithoutPermissions = await createUser();
|
||||||
|
const token = createAuthTokenByUserId(userWithoutPermissions.id);
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post('/graphql')
|
.post('/graphql')
|
||||||
.set('Authorization', 'invalid-token')
|
.set('Authorization', token)
|
||||||
.send({ query })
|
.send({ query })
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
expect(response.body.errors).toBeDefined();
|
||||||
expect(response.body.errors[0].message).toEqual('Not Authorised!');
|
expect(response.body.errors[0].message).toEqual('Not authorized!');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with authenticated user', () => {
|
describe('and with correct permissions', () => {
|
||||||
describe('and without permissions', () => {
|
let role, currentUser, anotherUser, token, requestObject;
|
||||||
it('should throw not authorized error', async () => {
|
|
||||||
const userWithoutPermissions = await createUser();
|
|
||||||
const token = createAuthTokenByUserId(userWithoutPermissions.id);
|
|
||||||
|
|
||||||
const response = await request(app)
|
beforeEach(async () => {
|
||||||
.post('/graphql')
|
role = await createRole({
|
||||||
.set('Authorization', token)
|
key: 'sample',
|
||||||
.send({ query })
|
name: 'sample',
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
|
||||||
expect(response.body.errors[0].message).toEqual('Not authorized!');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await createPermission({
|
||||||
|
action: 'read',
|
||||||
|
subject: 'User',
|
||||||
|
roleId: role.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
currentUser = await createUser({
|
||||||
|
roleId: role.id,
|
||||||
|
fullName: 'Current User',
|
||||||
|
});
|
||||||
|
|
||||||
|
anotherUser = await createUser({
|
||||||
|
roleId: role.id,
|
||||||
|
fullName: 'Another User',
|
||||||
|
});
|
||||||
|
|
||||||
|
token = createAuthTokenByUserId(currentUser.id);
|
||||||
|
requestObject = request(app).post('/graphql').set('Authorization', token);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('and with correct permissions', () => {
|
it('should return users data', async () => {
|
||||||
let role, currentUser, anotherUser, token, requestObject;
|
const response = await requestObject.send({ query }).expect(200);
|
||||||
|
|
||||||
beforeEach(async () => {
|
const expectedResponsePayload = {
|
||||||
role = await createRole({
|
data: {
|
||||||
key: 'sample',
|
getUsers: {
|
||||||
name: 'sample',
|
edges: [
|
||||||
});
|
{
|
||||||
|
node: {
|
||||||
await createPermission({
|
email: anotherUser.email,
|
||||||
action: 'read',
|
fullName: anotherUser.fullName,
|
||||||
subject: 'User',
|
id: anotherUser.id,
|
||||||
roleId: role.id,
|
role: {
|
||||||
});
|
id: role.id,
|
||||||
|
name: role.name,
|
||||||
currentUser = await createUser({
|
|
||||||
roleId: role.id,
|
|
||||||
fullName: 'Current User',
|
|
||||||
});
|
|
||||||
|
|
||||||
anotherUser = await createUser({
|
|
||||||
roleId: role.id,
|
|
||||||
fullName: 'Another User',
|
|
||||||
});
|
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
requestObject = request(app)
|
|
||||||
.post('/graphql')
|
|
||||||
.set('Authorization', token);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return users data', async () => {
|
|
||||||
const response = await requestObject.send({ query }).expect(200);
|
|
||||||
|
|
||||||
const expectedResponsePayload = {
|
|
||||||
data: {
|
|
||||||
getUsers: {
|
|
||||||
edges: [
|
|
||||||
{
|
|
||||||
node: {
|
|
||||||
email: anotherUser.email,
|
|
||||||
fullName: anotherUser.fullName,
|
|
||||||
id: anotherUser.id,
|
|
||||||
role: {
|
|
||||||
id: role.id,
|
|
||||||
name: role.name,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
node: {
|
|
||||||
email: currentUser.email,
|
|
||||||
fullName: currentUser.fullName,
|
|
||||||
id: currentUser.id,
|
|
||||||
role: {
|
|
||||||
id: role.id,
|
|
||||||
name: role.name,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
pageInfo: {
|
|
||||||
currentPage: 1,
|
|
||||||
totalPages: 1,
|
|
||||||
},
|
},
|
||||||
totalCount: 2,
|
{
|
||||||
|
node: {
|
||||||
|
email: currentUser.email,
|
||||||
|
fullName: currentUser.fullName,
|
||||||
|
id: currentUser.id,
|
||||||
|
role: {
|
||||||
|
id: role.id,
|
||||||
|
name: role.name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
pageInfo: {
|
||||||
|
currentPage: 1,
|
||||||
|
totalPages: 1,
|
||||||
},
|
},
|
||||||
|
totalCount: 2,
|
||||||
},
|
},
|
||||||
};
|
},
|
||||||
|
};
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedResponsePayload);
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not return users data with password', async () => {
|
it('should not return users data with password', async () => {
|
||||||
const query = `
|
const query = `
|
||||||
query {
|
query {
|
||||||
getUsers(limit: 10, offset: 0) {
|
getUsers(limit: 10, offset: 0) {
|
||||||
pageInfo {
|
pageInfo {
|
||||||
@@ -153,13 +137,12 @@ describe('graphQL getUsers query', () => {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const response = await requestObject.send({ query }).expect(400);
|
const response = await requestObject.send({ query }).expect(400);
|
||||||
|
|
||||||
expect(response.body.errors).toBeDefined();
|
expect(response.body.errors).toBeDefined();
|
||||||
expect(response.body.errors[0].message).toEqual(
|
expect(response.body.errors[0].message).toEqual(
|
||||||
'Cannot query field "password" on type "User".'
|
'Cannot query field "password" on type "User".'
|
||||||
);
|
);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -3,7 +3,7 @@ import jwt from 'jsonwebtoken';
|
|||||||
import appConfig from '../config/app.js';
|
import appConfig from '../config/app.js';
|
||||||
import User from '../models/user.js';
|
import User from '../models/user.js';
|
||||||
|
|
||||||
const isAuthenticated = rule()(async (_parent, _args, req) => {
|
export const isAuthenticated = async (_parent, _args, req) => {
|
||||||
const token = req.headers['authorization'];
|
const token = req.headers['authorization'];
|
||||||
|
|
||||||
if (token == null) return false;
|
if (token == null) return false;
|
||||||
@@ -26,29 +26,32 @@ const isAuthenticated = rule()(async (_parent, _args, req) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
const authentication = shield(
|
const isAuthenticatedRule = rule()(isAuthenticated);
|
||||||
{
|
|
||||||
Query: {
|
export const authenticationRules = {
|
||||||
'*': isAuthenticated,
|
Query: {
|
||||||
getAutomatischInfo: allow,
|
'*': isAuthenticatedRule,
|
||||||
getConfig: allow,
|
getAutomatischInfo: allow,
|
||||||
getNotifications: allow,
|
getConfig: allow,
|
||||||
healthcheck: allow,
|
getNotifications: allow,
|
||||||
listSamlAuthProviders: allow,
|
healthcheck: allow,
|
||||||
},
|
listSamlAuthProviders: allow,
|
||||||
Mutation: {
|
|
||||||
'*': isAuthenticated,
|
|
||||||
forgotPassword: allow,
|
|
||||||
login: allow,
|
|
||||||
registerUser: allow,
|
|
||||||
resetPassword: allow,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
Mutation: {
|
||||||
allowExternalErrors: true,
|
'*': isAuthenticatedRule,
|
||||||
}
|
forgotPassword: allow,
|
||||||
);
|
login: allow,
|
||||||
|
registerUser: allow,
|
||||||
|
resetPassword: allow,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const authenticationOptions = {
|
||||||
|
allowExternalErrors: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const authentication = shield(authenticationRules, authenticationOptions);
|
||||||
|
|
||||||
export default authentication;
|
export default authentication;
|
||||||
|
78
packages/backend/src/helpers/authentication.test.js
Normal file
78
packages/backend/src/helpers/authentication.test.js
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import { describe, it, expect, vi } from 'vitest';
|
||||||
|
import { allow } from 'graphql-shield';
|
||||||
|
import jwt from 'jsonwebtoken';
|
||||||
|
import User from '../models/user.js';
|
||||||
|
import { isAuthenticated, authenticationRules } from './authentication.js';
|
||||||
|
|
||||||
|
vi.mock('jsonwebtoken');
|
||||||
|
vi.mock('../models/user.js');
|
||||||
|
|
||||||
|
describe('isAuthenticated', () => {
|
||||||
|
it('should return false if no token is provided', async () => {
|
||||||
|
const req = { headers: {} };
|
||||||
|
expect(await isAuthenticated(null, null, req)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false if token is invalid', async () => {
|
||||||
|
jwt.verify.mockImplementation(() => {
|
||||||
|
throw new Error('invalid token');
|
||||||
|
});
|
||||||
|
|
||||||
|
const req = { headers: { authorization: 'invalidToken' } };
|
||||||
|
expect(await isAuthenticated(null, null, req)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true if token is valid', async () => {
|
||||||
|
jwt.verify.mockReturnValue({ userId: '123' });
|
||||||
|
|
||||||
|
User.query.mockReturnValue({
|
||||||
|
findById: vi.fn().mockReturnValue({
|
||||||
|
leftJoinRelated: vi.fn().mockReturnThis(),
|
||||||
|
withGraphFetched: vi
|
||||||
|
.fn()
|
||||||
|
.mockResolvedValue({ id: '123', role: {}, permissions: {} }),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const req = { headers: { authorization: 'validToken' } };
|
||||||
|
expect(await isAuthenticated(null, null, req)).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('authentication rules', () => {
|
||||||
|
const getQueryAndMutationNames = (rules) => {
|
||||||
|
const queries = Object.keys(rules.Query || {});
|
||||||
|
const mutations = Object.keys(rules.Mutation || {});
|
||||||
|
return { queries, mutations };
|
||||||
|
};
|
||||||
|
|
||||||
|
const { queries, mutations } = getQueryAndMutationNames(authenticationRules);
|
||||||
|
|
||||||
|
describe('for queries', () => {
|
||||||
|
queries.forEach((query) => {
|
||||||
|
it(`should apply correct rule for query: ${query}`, () => {
|
||||||
|
const ruleApplied = authenticationRules.Query[query];
|
||||||
|
|
||||||
|
if (query === '*') {
|
||||||
|
expect(ruleApplied.func).toBe(isAuthenticated);
|
||||||
|
} else {
|
||||||
|
expect(ruleApplied).toEqual(allow);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('for mutations', () => {
|
||||||
|
mutations.forEach((mutation) => {
|
||||||
|
it(`should apply correct rule for mutation: ${mutation}`, () => {
|
||||||
|
const ruleApplied = authenticationRules.Mutation[mutation];
|
||||||
|
|
||||||
|
if (mutation === '*') {
|
||||||
|
expect(ruleApplied.func).toBe(isAuthenticated);
|
||||||
|
} else {
|
||||||
|
expect(ruleApplied).toBe(allow);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@@ -32,6 +32,15 @@ export default defineConfig({
|
|||||||
],
|
],
|
||||||
sidebar: {
|
sidebar: {
|
||||||
'/apps/': [
|
'/apps/': [
|
||||||
|
{
|
||||||
|
text: 'Better Stack',
|
||||||
|
collapsible: true,
|
||||||
|
collapsed: true,
|
||||||
|
items: [
|
||||||
|
{ text: 'Actions', link: '/apps/better-stack/actions' },
|
||||||
|
{ text: 'Connection', link: '/apps/better-stack/connection' },
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
text: 'Carbone',
|
text: 'Carbone',
|
||||||
collapsible: true,
|
collapsible: true,
|
||||||
@@ -305,7 +314,7 @@ export default defineConfig({
|
|||||||
collapsed: true,
|
collapsed: true,
|
||||||
items: [
|
items: [
|
||||||
{ text: 'Actions', link: '/apps/removebg/actions' },
|
{ text: 'Actions', link: '/apps/removebg/actions' },
|
||||||
{ text: 'Connection', link: '/apps/removebg/connection' }
|
{ text: 'Connection', link: '/apps/removebg/connection' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
16
packages/docs/pages/apps/better-stack/actions.md
Normal file
16
packages/docs/pages/apps/better-stack/actions.md
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
favicon: /favicons/better-stack.svg
|
||||||
|
items:
|
||||||
|
- name: Acknowledge incident
|
||||||
|
desc: Acknowledges an incident.
|
||||||
|
- name: Create incident
|
||||||
|
desc: Creates an incident that informs the team.
|
||||||
|
- name: Resolve incident
|
||||||
|
desc: Resolves an incident.
|
||||||
|
---
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import CustomListing from '../../components/CustomListing.vue'
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<CustomListing />
|
14
packages/docs/pages/apps/better-stack/connection.md
Normal file
14
packages/docs/pages/apps/better-stack/connection.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# Better Stack
|
||||||
|
|
||||||
|
:::info
|
||||||
|
This page explains the steps you need to follow to set up the Better Stack
|
||||||
|
connection in Automatisch. If any of the steps are outdated, please let us know!
|
||||||
|
:::
|
||||||
|
|
||||||
|
1. Login to your Better Stack account: [https://betterstack.com/](https://betterstack.com/).
|
||||||
|
2. Click on the team name bottom left and select **Manage Teams** option.
|
||||||
|
3. Click on the three dots icon of your team and select **manage** option.
|
||||||
|
4. Click on the **API tokens** tab.
|
||||||
|
5. Copy the token next to **Direct API tokens** to the `API Key` field on Automatisch.
|
||||||
|
6. Fill the screen name on Automatisch.
|
||||||
|
7. Now, you can start using the Better Stack connection with Automatisch.
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
The following integrations are currently supported by Automatisch.
|
The following integrations are currently supported by Automatisch.
|
||||||
|
|
||||||
|
- [Better Stack](/apps/better-stack/actions)
|
||||||
- [Carbone](/apps/carbone/actions)
|
- [Carbone](/apps/carbone/actions)
|
||||||
- [DeepL](/apps/deepl/actions)
|
- [DeepL](/apps/deepl/actions)
|
||||||
- [Delay](/apps/delay/actions)
|
- [Delay](/apps/delay/actions)
|
||||||
|
21
packages/docs/pages/public/favicons/better-stack.svg
Normal file
21
packages/docs/pages/public/favicons/better-stack.svg
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" standalone="no"?>
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
||||||
|
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||||
|
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="200.000000pt" height="200.000000pt" viewBox="0 0 200.000000 200.000000"
|
||||||
|
preserveAspectRatio="xMidYMid meet">
|
||||||
|
|
||||||
|
<g transform="translate(0.000000,200.000000) scale(0.100000,-0.100000)"
|
||||||
|
fill="#000000" stroke="none">
|
||||||
|
<path d="M0 1000 l0 -1000 1000 0 1000 0 0 1000 0 1000 -1000 0 -1000 0 0
|
||||||
|
-1000z m1162 460 c14 -11 113 -184 232 -408 228 -429 231 -439 175 -486 -35
|
||||||
|
-30 -30 -29 -140 -15 -89 12 -123 25 -152 56 -9 11 -72 147 -140 304 -113 263
|
||||||
|
-124 284 -149 287 -14 2 -29 10 -32 17 -8 21 67 214 94 242 28 29 78 30 112 3z
|
||||||
|
m-340 -148 c10 -10 72 -175 139 -367 114 -325 121 -351 108 -374 -8 -14 -27
|
||||||
|
-32 -41 -41 -25 -13 -34 -12 -126 18 -55 18 -111 43 -125 56 -19 17 -40 67
|
||||||
|
-76 182 -36 112 -58 164 -73 176 l-22 16 27 99 c63 224 66 232 95 248 31 17
|
||||||
|
69 12 94 -13z m-314 -219 c16 -15 26 -59 56 -243 42 -262 43 -285 17 -300 -11
|
||||||
|
-5 -24 -10 -30 -10 -19 0 -140 114 -150 141 -7 20 -4 76 10 191 10 90 19 171
|
||||||
|
19 181 0 18 33 57 49 57 5 0 18 -8 29 -17z"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.1 KiB |
Reference in New Issue
Block a user