ci: Refactor cli tests to speed up CI (no-changelog) (#5718)
* ci: Refactor cli tests to speed up CI (no-changelog) * upgrade jest to address memory leaks
This commit is contained in:
committed by
GitHub
parent
be172cb720
commit
6242cac53b
@@ -1,24 +1,25 @@
|
||||
import express from 'express';
|
||||
|
||||
import type { SuperAgentTest } from 'supertest';
|
||||
import { UserSettings } from 'n8n-core';
|
||||
|
||||
import * as Db from '@/Db';
|
||||
import type { Role } from '@db/entities/Role';
|
||||
import type { User } from '@db/entities/User';
|
||||
import { RESPONSE_ERROR_MESSAGES } from '@/constants';
|
||||
import { randomApiKey, randomName, randomString } from '../shared/random';
|
||||
import * as utils from '../shared/utils';
|
||||
import type { CredentialPayload, SaveCredentialFunction } from '../shared/types';
|
||||
import * as testDb from '../shared/testDb';
|
||||
|
||||
let app: express.Application;
|
||||
let globalOwnerRole: Role;
|
||||
let globalMemberRole: Role;
|
||||
let credentialOwnerRole: Role;
|
||||
let owner: User;
|
||||
let member: User;
|
||||
let authOwnerAgent: SuperAgentTest;
|
||||
let authMemberAgent: SuperAgentTest;
|
||||
|
||||
let saveCredential: SaveCredentialFunction;
|
||||
|
||||
beforeAll(async () => {
|
||||
app = await utils.initTestServer({
|
||||
const app = await utils.initTestServer({
|
||||
endpointGroups: ['publicApi'],
|
||||
applyAuth: false,
|
||||
enablePublicAPI: true,
|
||||
@@ -26,334 +27,265 @@ beforeAll(async () => {
|
||||
|
||||
utils.initConfigFile();
|
||||
|
||||
const [fetchedGlobalOwnerRole, fetchedGlobalMemberRole, _, fetchedCredentialOwnerRole] =
|
||||
const [globalOwnerRole, fetchedGlobalMemberRole, _, fetchedCredentialOwnerRole] =
|
||||
await testDb.getAllRoles();
|
||||
|
||||
globalOwnerRole = fetchedGlobalOwnerRole;
|
||||
globalMemberRole = fetchedGlobalMemberRole;
|
||||
credentialOwnerRole = fetchedCredentialOwnerRole;
|
||||
|
||||
owner = await testDb.addApiKey(await testDb.createUserShell(globalOwnerRole));
|
||||
member = await testDb.createUser({ globalRole: globalMemberRole, apiKey: randomApiKey() });
|
||||
|
||||
authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
version: 1,
|
||||
auth: true,
|
||||
user: owner,
|
||||
});
|
||||
authMemberAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
version: 1,
|
||||
auth: true,
|
||||
user: member,
|
||||
});
|
||||
|
||||
saveCredential = testDb.affixRoleToSaveCredential(credentialOwnerRole);
|
||||
|
||||
utils.initCredentialsTypes();
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await testDb.truncate(['User', 'SharedCredentials', 'Credentials']);
|
||||
await testDb.truncate(['SharedCredentials', 'Credentials']);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await testDb.terminate();
|
||||
});
|
||||
|
||||
test('POST /credentials should create credentials', async () => {
|
||||
let ownerShell = await testDb.createUserShell(globalOwnerRole);
|
||||
ownerShell = await testDb.addApiKey(ownerShell);
|
||||
describe('POST /credentials', () => {
|
||||
test('should create credentials', async () => {
|
||||
const payload = {
|
||||
name: 'test credential',
|
||||
type: 'githubApi',
|
||||
data: {
|
||||
accessToken: 'abcdefghijklmnopqrstuvwxyz',
|
||||
user: 'test',
|
||||
server: 'testServer',
|
||||
},
|
||||
};
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
version: 1,
|
||||
auth: true,
|
||||
user: ownerShell,
|
||||
});
|
||||
const payload = {
|
||||
name: 'test credential',
|
||||
type: 'githubApi',
|
||||
data: {
|
||||
accessToken: 'abcdefghijklmnopqrstuvwxyz',
|
||||
user: 'test',
|
||||
server: 'testServer',
|
||||
},
|
||||
};
|
||||
const response = await authOwnerAgent.post('/credentials').send(payload);
|
||||
|
||||
const response = await authOwnerAgent.post('/credentials').send(payload);
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
const { id, name, type } = response.body;
|
||||
|
||||
const { id, name, type } = response.body;
|
||||
expect(name).toBe(payload.name);
|
||||
expect(type).toBe(payload.type);
|
||||
|
||||
expect(name).toBe(payload.name);
|
||||
expect(type).toBe(payload.type);
|
||||
const credential = await Db.collections.Credentials.findOneByOrFail({ id });
|
||||
|
||||
const credential = await Db.collections.Credentials.findOneByOrFail({ id });
|
||||
expect(credential.name).toBe(payload.name);
|
||||
expect(credential.type).toBe(payload.type);
|
||||
expect(credential.data).not.toBe(payload.data);
|
||||
|
||||
expect(credential.name).toBe(payload.name);
|
||||
expect(credential.type).toBe(payload.type);
|
||||
expect(credential.data).not.toBe(payload.data);
|
||||
const sharedCredential = await Db.collections.SharedCredentials.findOneOrFail({
|
||||
relations: ['user', 'credentials', 'role'],
|
||||
where: { credentialsId: credential.id, userId: owner.id },
|
||||
});
|
||||
|
||||
const sharedCredential = await Db.collections.SharedCredentials.findOneOrFail({
|
||||
relations: ['user', 'credentials', 'role'],
|
||||
where: { credentialsId: credential.id, userId: ownerShell.id },
|
||||
expect(sharedCredential.role).toEqual(credentialOwnerRole);
|
||||
expect(sharedCredential.credentials.name).toBe(payload.name);
|
||||
});
|
||||
|
||||
expect(sharedCredential.role).toEqual(credentialOwnerRole);
|
||||
expect(sharedCredential.credentials.name).toBe(payload.name);
|
||||
test('should fail with invalid inputs', async () => {
|
||||
await Promise.all(
|
||||
INVALID_PAYLOADS.map(async (invalidPayload) => {
|
||||
const response = await authOwnerAgent.post('/credentials').send(invalidPayload);
|
||||
expect(response.statusCode === 400 || response.statusCode === 415).toBe(true);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('should fail with missing encryption key', async () => {
|
||||
const mock = jest.spyOn(UserSettings, 'getEncryptionKey');
|
||||
mock.mockRejectedValue(new Error(RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY));
|
||||
|
||||
const response = await authOwnerAgent.post('/credentials').send(credentialPayload());
|
||||
|
||||
expect(response.statusCode).toBe(500);
|
||||
|
||||
mock.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
test('POST /credentials should fail with invalid inputs', async () => {
|
||||
let ownerShell = await testDb.createUserShell(globalOwnerRole);
|
||||
ownerShell = await testDb.addApiKey(ownerShell);
|
||||
describe('DELETE /credentials/:id', () => {
|
||||
test('should delete owned cred for owner', async () => {
|
||||
const savedCredential = await saveCredential(dbCredential(), { user: owner });
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
version: 1,
|
||||
auth: true,
|
||||
user: ownerShell,
|
||||
const response = await authOwnerAgent.delete(`/credentials/${savedCredential.id}`);
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
const { name, type } = response.body;
|
||||
|
||||
expect(name).toBe(savedCredential.name);
|
||||
expect(type).toBe(savedCredential.type);
|
||||
|
||||
const deletedCredential = await Db.collections.Credentials.findOneBy({
|
||||
id: savedCredential.id,
|
||||
});
|
||||
|
||||
expect(deletedCredential).toBeNull(); // deleted
|
||||
|
||||
const deletedSharedCredential = await Db.collections.SharedCredentials.findOneBy({});
|
||||
|
||||
expect(deletedSharedCredential).toBeNull(); // deleted
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
INVALID_PAYLOADS.map(async (invalidPayload) => {
|
||||
const response = await authOwnerAgent.post('/credentials').send(invalidPayload);
|
||||
expect(response.statusCode === 400 || response.statusCode === 415).toBe(true);
|
||||
}),
|
||||
);
|
||||
test('should delete non-owned cred for owner', async () => {
|
||||
const savedCredential = await saveCredential(dbCredential(), { user: member });
|
||||
|
||||
const response = await authOwnerAgent.delete(`/credentials/${savedCredential.id}`);
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
const deletedCredential = await Db.collections.Credentials.findOneBy({
|
||||
id: savedCredential.id,
|
||||
});
|
||||
|
||||
expect(deletedCredential).toBeNull(); // deleted
|
||||
|
||||
const deletedSharedCredential = await Db.collections.SharedCredentials.findOneBy({});
|
||||
|
||||
expect(deletedSharedCredential).toBeNull(); // deleted
|
||||
});
|
||||
|
||||
test('should delete owned cred for member', async () => {
|
||||
const savedCredential = await saveCredential(dbCredential(), { user: member });
|
||||
|
||||
const response = await authMemberAgent.delete(`/credentials/${savedCredential.id}`);
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
const { name, type } = response.body;
|
||||
|
||||
expect(name).toBe(savedCredential.name);
|
||||
expect(type).toBe(savedCredential.type);
|
||||
|
||||
const deletedCredential = await Db.collections.Credentials.findOneBy({
|
||||
id: savedCredential.id,
|
||||
});
|
||||
|
||||
expect(deletedCredential).toBeNull(); // deleted
|
||||
|
||||
const deletedSharedCredential = await Db.collections.SharedCredentials.findOneBy({});
|
||||
|
||||
expect(deletedSharedCredential).toBeNull(); // deleted
|
||||
});
|
||||
|
||||
test('should delete owned cred for member but leave others untouched', async () => {
|
||||
const anotherMember = await testDb.createUser({
|
||||
globalRole: globalMemberRole,
|
||||
apiKey: randomApiKey(),
|
||||
});
|
||||
|
||||
const savedCredential = await saveCredential(dbCredential(), { user: member });
|
||||
const notToBeChangedCredential = await saveCredential(dbCredential(), { user: member });
|
||||
const notToBeChangedCredential2 = await saveCredential(dbCredential(), {
|
||||
user: anotherMember,
|
||||
});
|
||||
|
||||
const response = await authMemberAgent.delete(`/credentials/${savedCredential.id}`);
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
const { name, type } = response.body;
|
||||
|
||||
expect(name).toBe(savedCredential.name);
|
||||
expect(type).toBe(savedCredential.type);
|
||||
|
||||
const deletedCredential = await Db.collections.Credentials.findOneBy({
|
||||
id: savedCredential.id,
|
||||
});
|
||||
|
||||
expect(deletedCredential).toBeNull(); // deleted
|
||||
|
||||
const deletedSharedCredential = await Db.collections.SharedCredentials.findOne({
|
||||
where: {
|
||||
credentialsId: savedCredential.id,
|
||||
},
|
||||
});
|
||||
|
||||
expect(deletedSharedCredential).toBeNull(); // deleted
|
||||
|
||||
await Promise.all(
|
||||
[notToBeChangedCredential, notToBeChangedCredential2].map(async (credential) => {
|
||||
const untouchedCredential = await Db.collections.Credentials.findOneBy({
|
||||
id: credential.id,
|
||||
});
|
||||
|
||||
expect(untouchedCredential).toEqual(credential); // not deleted
|
||||
|
||||
const untouchedSharedCredential = await Db.collections.SharedCredentials.findOne({
|
||||
where: {
|
||||
credentialsId: credential.id,
|
||||
},
|
||||
});
|
||||
|
||||
expect(untouchedSharedCredential).toBeDefined(); // not deleted
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('should not delete non-owned cred for member', async () => {
|
||||
const savedCredential = await saveCredential(dbCredential(), { user: owner });
|
||||
|
||||
const response = await authMemberAgent.delete(`/credentials/${savedCredential.id}`);
|
||||
|
||||
expect(response.statusCode).toBe(404);
|
||||
|
||||
const shellCredential = await Db.collections.Credentials.findOneBy({
|
||||
id: savedCredential.id,
|
||||
});
|
||||
|
||||
expect(shellCredential).toBeDefined(); // not deleted
|
||||
|
||||
const deletedSharedCredential = await Db.collections.SharedCredentials.findOneBy({});
|
||||
|
||||
expect(deletedSharedCredential).toBeDefined(); // not deleted
|
||||
});
|
||||
|
||||
test('should fail if cred not found', async () => {
|
||||
const response = await authOwnerAgent.delete('/credentials/123');
|
||||
|
||||
expect(response.statusCode).toBe(404);
|
||||
});
|
||||
});
|
||||
|
||||
test('POST /credentials should fail with missing encryption key', async () => {
|
||||
const mock = jest.spyOn(UserSettings, 'getEncryptionKey');
|
||||
mock.mockRejectedValue(new Error(RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY));
|
||||
describe('GET /credentials/schema/:credentialType', () => {
|
||||
test('should fail due to not found type', async () => {
|
||||
const response = await authOwnerAgent.get('/credentials/schema/testing');
|
||||
|
||||
let ownerShell = await testDb.createUserShell(globalOwnerRole);
|
||||
ownerShell = await testDb.addApiKey(ownerShell);
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
version: 1,
|
||||
auth: true,
|
||||
user: ownerShell,
|
||||
expect(response.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
const response = await authOwnerAgent.post('/credentials').send(credentialPayload());
|
||||
test('should retrieve credential type', async () => {
|
||||
const response = await authOwnerAgent.get('/credentials/schema/githubApi');
|
||||
|
||||
expect(response.statusCode).toBe(500);
|
||||
const { additionalProperties, type, properties, required } = response.body;
|
||||
|
||||
mock.mockRestore();
|
||||
});
|
||||
|
||||
test('DELETE /credentials/:id should delete owned cred for owner', async () => {
|
||||
let ownerShell = await testDb.createUserShell(globalOwnerRole);
|
||||
ownerShell = await testDb.addApiKey(ownerShell);
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
version: 1,
|
||||
auth: true,
|
||||
user: ownerShell,
|
||||
expect(additionalProperties).toBe(false);
|
||||
expect(type).toBe('object');
|
||||
expect(properties.server).toBeDefined();
|
||||
expect(properties.server.type).toBe('string');
|
||||
expect(properties.user.type).toBeDefined();
|
||||
expect(properties.user.type).toBe('string');
|
||||
expect(properties.accessToken.type).toBeDefined();
|
||||
expect(properties.accessToken.type).toBe('string');
|
||||
expect(required).toEqual(expect.arrayContaining(['server', 'user', 'accessToken']));
|
||||
expect(response.statusCode).toBe(200);
|
||||
});
|
||||
|
||||
const savedCredential = await saveCredential(dbCredential(), { user: ownerShell });
|
||||
|
||||
const response = await authOwnerAgent.delete(`/credentials/${savedCredential.id}`);
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
const { name, type } = response.body;
|
||||
|
||||
expect(name).toBe(savedCredential.name);
|
||||
expect(type).toBe(savedCredential.type);
|
||||
|
||||
const deletedCredential = await Db.collections.Credentials.findOneBy({ id: savedCredential.id });
|
||||
|
||||
expect(deletedCredential).toBeNull(); // deleted
|
||||
|
||||
const deletedSharedCredential = await Db.collections.SharedCredentials.findOneBy({});
|
||||
|
||||
expect(deletedSharedCredential).toBeNull(); // deleted
|
||||
});
|
||||
|
||||
test('DELETE /credentials/:id should delete non-owned cred for owner', async () => {
|
||||
let ownerShell = await testDb.createUserShell(globalOwnerRole);
|
||||
ownerShell = await testDb.addApiKey(ownerShell);
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
version: 1,
|
||||
auth: true,
|
||||
user: ownerShell,
|
||||
});
|
||||
|
||||
const member = await testDb.createUser({ globalRole: globalMemberRole });
|
||||
|
||||
const savedCredential = await saveCredential(dbCredential(), { user: member });
|
||||
|
||||
const response = await authOwnerAgent.delete(`/credentials/${savedCredential.id}`);
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
const deletedCredential = await Db.collections.Credentials.findOneBy({ id: savedCredential.id });
|
||||
|
||||
expect(deletedCredential).toBeNull(); // deleted
|
||||
|
||||
const deletedSharedCredential = await Db.collections.SharedCredentials.findOneBy({});
|
||||
|
||||
expect(deletedSharedCredential).toBeNull(); // deleted
|
||||
});
|
||||
|
||||
test('DELETE /credentials/:id should delete owned cred for member', async () => {
|
||||
const member = await testDb.createUser({ globalRole: globalMemberRole, apiKey: randomApiKey() });
|
||||
|
||||
const authMemberAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
version: 1,
|
||||
auth: true,
|
||||
user: member,
|
||||
});
|
||||
|
||||
const savedCredential = await saveCredential(dbCredential(), { user: member });
|
||||
|
||||
const response = await authMemberAgent.delete(`/credentials/${savedCredential.id}`);
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
const { name, type } = response.body;
|
||||
|
||||
expect(name).toBe(savedCredential.name);
|
||||
expect(type).toBe(savedCredential.type);
|
||||
|
||||
const deletedCredential = await Db.collections.Credentials.findOneBy({ id: savedCredential.id });
|
||||
|
||||
expect(deletedCredential).toBeNull(); // deleted
|
||||
|
||||
const deletedSharedCredential = await Db.collections.SharedCredentials.findOneBy({});
|
||||
|
||||
expect(deletedSharedCredential).toBeNull(); // deleted
|
||||
});
|
||||
|
||||
test('DELETE /credentials/:id should delete owned cred for member but leave others untouched', async () => {
|
||||
const member1 = await testDb.createUser({ globalRole: globalMemberRole, apiKey: randomApiKey() });
|
||||
const member2 = await testDb.createUser({ globalRole: globalMemberRole, apiKey: randomApiKey() });
|
||||
|
||||
const savedCredential = await saveCredential(dbCredential(), { user: member1 });
|
||||
const notToBeChangedCredential = await saveCredential(dbCredential(), { user: member1 });
|
||||
const notToBeChangedCredential2 = await saveCredential(dbCredential(), { user: member2 });
|
||||
|
||||
const authMemberAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
version: 1,
|
||||
auth: true,
|
||||
user: member1,
|
||||
});
|
||||
|
||||
const response = await authMemberAgent.delete(`/credentials/${savedCredential.id}`);
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
const { name, type } = response.body;
|
||||
|
||||
expect(name).toBe(savedCredential.name);
|
||||
expect(type).toBe(savedCredential.type);
|
||||
|
||||
const deletedCredential = await Db.collections.Credentials.findOneBy({ id: savedCredential.id });
|
||||
|
||||
expect(deletedCredential).toBeNull(); // deleted
|
||||
|
||||
const deletedSharedCredential = await Db.collections.SharedCredentials.findOne({
|
||||
where: {
|
||||
credentialsId: savedCredential.id,
|
||||
},
|
||||
});
|
||||
|
||||
expect(deletedSharedCredential).toBeNull(); // deleted
|
||||
|
||||
await Promise.all(
|
||||
[notToBeChangedCredential, notToBeChangedCredential2].map(async (credential) => {
|
||||
const untouchedCredential = await Db.collections.Credentials.findOneBy({ id: credential.id });
|
||||
|
||||
expect(untouchedCredential).toEqual(credential); // not deleted
|
||||
|
||||
const untouchedSharedCredential = await Db.collections.SharedCredentials.findOne({
|
||||
where: {
|
||||
credentialsId: credential.id,
|
||||
},
|
||||
});
|
||||
|
||||
expect(untouchedSharedCredential).toBeDefined(); // not deleted
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('DELETE /credentials/:id should not delete non-owned cred for member', async () => {
|
||||
const ownerShell = await testDb.createUserShell(globalOwnerRole);
|
||||
const member = await testDb.createUser({ globalRole: globalMemberRole, apiKey: randomApiKey() });
|
||||
|
||||
const authMemberAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
version: 1,
|
||||
auth: true,
|
||||
user: member,
|
||||
});
|
||||
const savedCredential = await saveCredential(dbCredential(), { user: ownerShell });
|
||||
|
||||
const response = await authMemberAgent.delete(`/credentials/${savedCredential.id}`);
|
||||
|
||||
expect(response.statusCode).toBe(404);
|
||||
|
||||
const shellCredential = await Db.collections.Credentials.findOneBy({ id: savedCredential.id });
|
||||
|
||||
expect(shellCredential).toBeDefined(); // not deleted
|
||||
|
||||
const deletedSharedCredential = await Db.collections.SharedCredentials.findOneBy({});
|
||||
|
||||
expect(deletedSharedCredential).toBeDefined(); // not deleted
|
||||
});
|
||||
|
||||
test('DELETE /credentials/:id should fail if cred not found', async () => {
|
||||
let ownerShell = await testDb.createUserShell(globalOwnerRole);
|
||||
ownerShell = await testDb.addApiKey(ownerShell);
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
version: 1,
|
||||
auth: true,
|
||||
user: ownerShell,
|
||||
});
|
||||
|
||||
const response = await authOwnerAgent.delete('/credentials/123');
|
||||
|
||||
expect(response.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
test('GET /credentials/schema/:credentialType should fail due to not found type', async () => {
|
||||
let ownerShell = await testDb.createUserShell(globalOwnerRole);
|
||||
ownerShell = await testDb.addApiKey(ownerShell);
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
version: 1,
|
||||
auth: true,
|
||||
user: ownerShell,
|
||||
});
|
||||
|
||||
const response = await authOwnerAgent.get('/credentials/schema/testing');
|
||||
|
||||
expect(response.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
test('GET /credentials/schema/:credentialType should retrieve credential type', async () => {
|
||||
let ownerShell = await testDb.createUserShell(globalOwnerRole);
|
||||
ownerShell = await testDb.addApiKey(ownerShell);
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
version: 1,
|
||||
auth: true,
|
||||
user: ownerShell,
|
||||
});
|
||||
|
||||
const response = await authOwnerAgent.get('/credentials/schema/githubApi');
|
||||
|
||||
const { additionalProperties, type, properties, required } = response.body;
|
||||
|
||||
expect(additionalProperties).toBe(false);
|
||||
expect(type).toBe('object');
|
||||
expect(properties.server).toBeDefined();
|
||||
expect(properties.server.type).toBe('string');
|
||||
expect(properties.user.type).toBeDefined();
|
||||
expect(properties.user.type).toBe('string');
|
||||
expect(properties.accessToken.type).toBeDefined();
|
||||
expect(properties.accessToken.type).toBe('string');
|
||||
expect(required).toEqual(expect.arrayContaining(['server', 'user', 'accessToken']));
|
||||
expect(response.statusCode).toBe(200);
|
||||
});
|
||||
|
||||
const credentialPayload = (): CredentialPayload => ({
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import express from 'express';
|
||||
|
||||
import type { Application } from 'express';
|
||||
import type { SuperAgentTest } from 'supertest';
|
||||
import config from '@/config';
|
||||
import { Role } from '@db/entities/Role';
|
||||
import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
|
||||
import type { User } from '@db/entities/User';
|
||||
import type { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
|
||||
|
||||
import { randomApiKey } from '../shared/random';
|
||||
import * as utils from '../shared/utils';
|
||||
import * as testDb from '../shared/testDb';
|
||||
|
||||
let app: express.Application;
|
||||
let globalOwnerRole: Role;
|
||||
let app: Application;
|
||||
let owner: User;
|
||||
let authOwnerAgent: SuperAgentTest;
|
||||
let workflowRunner: ActiveWorkflowRunner;
|
||||
|
||||
beforeAll(async () => {
|
||||
@@ -19,7 +20,8 @@ beforeAll(async () => {
|
||||
enablePublicAPI: true,
|
||||
});
|
||||
|
||||
globalOwnerRole = await testDb.getGlobalOwnerRole();
|
||||
const globalOwnerRole = await testDb.getGlobalOwnerRole();
|
||||
owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
|
||||
|
||||
await utils.initBinaryManager();
|
||||
await utils.initNodeTypes();
|
||||
@@ -31,13 +33,19 @@ beforeEach(async () => {
|
||||
await testDb.truncate([
|
||||
'SharedCredentials',
|
||||
'SharedWorkflow',
|
||||
'User',
|
||||
'Workflow',
|
||||
'Credentials',
|
||||
'Execution',
|
||||
'Settings',
|
||||
]);
|
||||
|
||||
authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
auth: true,
|
||||
user: owner,
|
||||
version: 1,
|
||||
});
|
||||
|
||||
config.set('userManagement.disabled', false);
|
||||
config.set('userManagement.isInstanceOwnerSetUp', true);
|
||||
});
|
||||
@@ -50,270 +58,27 @@ afterAll(async () => {
|
||||
await testDb.terminate();
|
||||
});
|
||||
|
||||
test('GET /executions/:id should fail due to missing API Key', async () => {
|
||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
||||
const testWithAPIKey =
|
||||
(method: 'get' | 'post' | 'put' | 'delete', url: string, apiKey: string | null) => async () => {
|
||||
authOwnerAgent.set({ 'X-N8N-API-KEY': apiKey });
|
||||
const response = await authOwnerAgent[method](url);
|
||||
expect(response.statusCode).toBe(401);
|
||||
};
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
auth: true,
|
||||
user: owner,
|
||||
version: 1,
|
||||
});
|
||||
describe('GET /executions/:id', () => {
|
||||
test('should fail due to missing API Key', testWithAPIKey('get', '/executions/1', null));
|
||||
|
||||
const response = await authOwnerAgent.get('/executions/1');
|
||||
test('should fail due to invalid API Key', testWithAPIKey('get', '/executions/1', 'abcXYZ'));
|
||||
|
||||
expect(response.statusCode).toBe(401);
|
||||
});
|
||||
test('should get an execution', async () => {
|
||||
const workflow = await testDb.createWorkflow({}, owner);
|
||||
|
||||
test('GET /executions/:id should fail due to invalid API Key', async () => {
|
||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
|
||||
owner.apiKey = 'abcXYZ';
|
||||
const execution = await testDb.createSuccessfulExecution(workflow);
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
auth: true,
|
||||
user: owner,
|
||||
version: 1,
|
||||
});
|
||||
const response = await authOwnerAgent.get(`/executions/${execution.id}`);
|
||||
|
||||
const response = await authOwnerAgent.get('/executions/1');
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
expect(response.statusCode).toBe(401);
|
||||
});
|
||||
|
||||
test('GET /executions/:id should get an execution', async () => {
|
||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
auth: true,
|
||||
user: owner,
|
||||
version: 1,
|
||||
});
|
||||
|
||||
const workflow = await testDb.createWorkflow({}, owner);
|
||||
|
||||
const execution = await testDb.createSuccessfulExecution(workflow);
|
||||
|
||||
const response = await authOwnerAgent.get(`/executions/${execution.id}`);
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
const {
|
||||
id,
|
||||
finished,
|
||||
mode,
|
||||
retryOf,
|
||||
retrySuccessId,
|
||||
startedAt,
|
||||
stoppedAt,
|
||||
workflowId,
|
||||
waitTill,
|
||||
} = response.body;
|
||||
|
||||
expect(id).toBeDefined();
|
||||
expect(finished).toBe(true);
|
||||
expect(mode).toEqual(execution.mode);
|
||||
expect(retrySuccessId).toBeNull();
|
||||
expect(retryOf).toBeNull();
|
||||
expect(startedAt).not.toBeNull();
|
||||
expect(stoppedAt).not.toBeNull();
|
||||
expect(workflowId).toBe(execution.workflowId);
|
||||
expect(waitTill).toBeNull();
|
||||
});
|
||||
|
||||
test('DELETE /executions/:id should fail due to missing API Key', async () => {
|
||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
auth: true,
|
||||
user: owner,
|
||||
version: 1,
|
||||
});
|
||||
|
||||
const response = await authOwnerAgent.delete('/executions/1');
|
||||
|
||||
expect(response.statusCode).toBe(401);
|
||||
});
|
||||
|
||||
test('DELETE /executions/:id should fail due to invalid API Key', async () => {
|
||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
|
||||
owner.apiKey = 'abcXYZ';
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
auth: true,
|
||||
user: owner,
|
||||
version: 1,
|
||||
});
|
||||
|
||||
const response = await authOwnerAgent.delete('/executions/1');
|
||||
|
||||
expect(response.statusCode).toBe(401);
|
||||
});
|
||||
|
||||
test('DELETE /executions/:id should delete an execution', async () => {
|
||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
auth: true,
|
||||
user: owner,
|
||||
version: 1,
|
||||
});
|
||||
|
||||
const workflow = await testDb.createWorkflow({}, owner);
|
||||
|
||||
const execution = await testDb.createSuccessfulExecution(workflow);
|
||||
|
||||
const response = await authOwnerAgent.delete(`/executions/${execution.id}`);
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
const {
|
||||
id,
|
||||
finished,
|
||||
mode,
|
||||
retryOf,
|
||||
retrySuccessId,
|
||||
startedAt,
|
||||
stoppedAt,
|
||||
workflowId,
|
||||
waitTill,
|
||||
} = response.body;
|
||||
|
||||
expect(id).toBeDefined();
|
||||
expect(finished).toBe(true);
|
||||
expect(mode).toEqual(execution.mode);
|
||||
expect(retrySuccessId).toBeNull();
|
||||
expect(retryOf).toBeNull();
|
||||
expect(startedAt).not.toBeNull();
|
||||
expect(stoppedAt).not.toBeNull();
|
||||
expect(workflowId).toBe(execution.workflowId);
|
||||
expect(waitTill).toBeNull();
|
||||
});
|
||||
|
||||
test('GET /executions should fail due to missing API Key', async () => {
|
||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
auth: true,
|
||||
user: owner,
|
||||
version: 1,
|
||||
});
|
||||
|
||||
const response = await authOwnerAgent.get('/executions');
|
||||
|
||||
expect(response.statusCode).toBe(401);
|
||||
});
|
||||
|
||||
test('GET /executions should fail due to invalid API Key', async () => {
|
||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
|
||||
owner.apiKey = 'abcXYZ';
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
auth: true,
|
||||
user: owner,
|
||||
version: 1,
|
||||
});
|
||||
|
||||
const response = await authOwnerAgent.get('/executions');
|
||||
|
||||
expect(response.statusCode).toBe(401);
|
||||
});
|
||||
|
||||
test('GET /executions should retrieve all successful executions', async () => {
|
||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
auth: true,
|
||||
user: owner,
|
||||
version: 1,
|
||||
});
|
||||
|
||||
const workflow = await testDb.createWorkflow({}, owner);
|
||||
|
||||
const successfullExecution = await testDb.createSuccessfulExecution(workflow);
|
||||
|
||||
await testDb.createErrorExecution(workflow);
|
||||
|
||||
const response = await authOwnerAgent.get(`/executions`).query({
|
||||
status: 'success',
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.body.data.length).toBe(1);
|
||||
expect(response.body.nextCursor).toBe(null);
|
||||
|
||||
const {
|
||||
id,
|
||||
finished,
|
||||
mode,
|
||||
retryOf,
|
||||
retrySuccessId,
|
||||
startedAt,
|
||||
stoppedAt,
|
||||
workflowId,
|
||||
waitTill,
|
||||
} = response.body.data[0];
|
||||
|
||||
expect(id).toBeDefined();
|
||||
expect(finished).toBe(true);
|
||||
expect(mode).toEqual(successfullExecution.mode);
|
||||
expect(retrySuccessId).toBeNull();
|
||||
expect(retryOf).toBeNull();
|
||||
expect(startedAt).not.toBeNull();
|
||||
expect(stoppedAt).not.toBeNull();
|
||||
expect(workflowId).toBe(successfullExecution.workflowId);
|
||||
expect(waitTill).toBeNull();
|
||||
});
|
||||
|
||||
// failing on Postgres and MySQL - ref: https://github.com/n8n-io/n8n/pull/3834
|
||||
test.skip('GET /executions should paginate two executions', async () => {
|
||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
auth: true,
|
||||
user: owner,
|
||||
version: 1,
|
||||
});
|
||||
|
||||
const workflow = await testDb.createWorkflow({}, owner);
|
||||
|
||||
const firstSuccessfulExecution = await testDb.createSuccessfulExecution(workflow);
|
||||
|
||||
const secondSuccessfulExecution = await testDb.createSuccessfulExecution(workflow);
|
||||
|
||||
await testDb.createErrorExecution(workflow);
|
||||
|
||||
const firstExecutionResponse = await authOwnerAgent.get(`/executions`).query({
|
||||
status: 'success',
|
||||
limit: 1,
|
||||
});
|
||||
|
||||
expect(firstExecutionResponse.statusCode).toBe(200);
|
||||
expect(firstExecutionResponse.body.data.length).toBe(1);
|
||||
expect(firstExecutionResponse.body.nextCursor).toBeDefined();
|
||||
|
||||
const secondExecutionResponse = await authOwnerAgent.get(`/executions`).query({
|
||||
status: 'success',
|
||||
limit: 1,
|
||||
cursor: firstExecutionResponse.body.nextCursor,
|
||||
});
|
||||
|
||||
expect(secondExecutionResponse.statusCode).toBe(200);
|
||||
expect(secondExecutionResponse.body.data.length).toBe(1);
|
||||
expect(secondExecutionResponse.body.nextCursor).toBeNull();
|
||||
|
||||
const successfulExecutions = [firstSuccessfulExecution, secondSuccessfulExecution];
|
||||
const executions = [...firstExecutionResponse.body.data, ...secondExecutionResponse.body.data];
|
||||
|
||||
for (let i = 0; i < executions.length; i++) {
|
||||
const {
|
||||
id,
|
||||
finished,
|
||||
@@ -324,146 +89,33 @@ test.skip('GET /executions should paginate two executions', async () => {
|
||||
stoppedAt,
|
||||
workflowId,
|
||||
waitTill,
|
||||
} = executions[i];
|
||||
} = response.body;
|
||||
|
||||
expect(id).toBeDefined();
|
||||
expect(finished).toBe(true);
|
||||
expect(mode).toEqual(successfulExecutions[i].mode);
|
||||
expect(mode).toEqual(execution.mode);
|
||||
expect(retrySuccessId).toBeNull();
|
||||
expect(retryOf).toBeNull();
|
||||
expect(startedAt).not.toBeNull();
|
||||
expect(stoppedAt).not.toBeNull();
|
||||
expect(workflowId).toBe(successfulExecutions[i].workflowId);
|
||||
expect(workflowId).toBe(execution.workflowId);
|
||||
expect(waitTill).toBeNull();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('GET /executions should retrieve all error executions', async () => {
|
||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
|
||||
describe('DELETE /executions/:id', () => {
|
||||
test('should fail due to missing API Key', testWithAPIKey('delete', '/executions/1', null));
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
auth: true,
|
||||
user: owner,
|
||||
version: 1,
|
||||
});
|
||||
test('should fail due to invalid API Key', testWithAPIKey('delete', '/executions/1', 'abcXYZ'));
|
||||
|
||||
const workflow = await testDb.createWorkflow({}, owner);
|
||||
test('should delete an execution', async () => {
|
||||
const workflow = await testDb.createWorkflow({}, owner);
|
||||
const execution = await testDb.createSuccessfulExecution(workflow);
|
||||
|
||||
await testDb.createSuccessfulExecution(workflow);
|
||||
const response = await authOwnerAgent.delete(`/executions/${execution.id}`);
|
||||
|
||||
const errorExecution = await testDb.createErrorExecution(workflow);
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
const response = await authOwnerAgent.get(`/executions`).query({
|
||||
status: 'error',
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.body.data.length).toBe(1);
|
||||
expect(response.body.nextCursor).toBe(null);
|
||||
|
||||
const {
|
||||
id,
|
||||
finished,
|
||||
mode,
|
||||
retryOf,
|
||||
retrySuccessId,
|
||||
startedAt,
|
||||
stoppedAt,
|
||||
workflowId,
|
||||
waitTill,
|
||||
} = response.body.data[0];
|
||||
|
||||
expect(id).toBeDefined();
|
||||
expect(finished).toBe(false);
|
||||
expect(mode).toEqual(errorExecution.mode);
|
||||
expect(retrySuccessId).toBeNull();
|
||||
expect(retryOf).toBeNull();
|
||||
expect(startedAt).not.toBeNull();
|
||||
expect(stoppedAt).not.toBeNull();
|
||||
expect(workflowId).toBe(errorExecution.workflowId);
|
||||
expect(waitTill).toBeNull();
|
||||
});
|
||||
|
||||
test('GET /executions should return all waiting executions', async () => {
|
||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
auth: true,
|
||||
user: owner,
|
||||
version: 1,
|
||||
});
|
||||
|
||||
const workflow = await testDb.createWorkflow({}, owner);
|
||||
|
||||
await testDb.createSuccessfulExecution(workflow);
|
||||
|
||||
await testDb.createErrorExecution(workflow);
|
||||
|
||||
const waitingExecution = await testDb.createWaitingExecution(workflow);
|
||||
|
||||
const response = await authOwnerAgent.get(`/executions`).query({
|
||||
status: 'waiting',
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.body.data.length).toBe(1);
|
||||
expect(response.body.nextCursor).toBe(null);
|
||||
|
||||
const {
|
||||
id,
|
||||
finished,
|
||||
mode,
|
||||
retryOf,
|
||||
retrySuccessId,
|
||||
startedAt,
|
||||
stoppedAt,
|
||||
workflowId,
|
||||
waitTill,
|
||||
} = response.body.data[0];
|
||||
|
||||
expect(id).toBeDefined();
|
||||
expect(finished).toBe(false);
|
||||
expect(mode).toEqual(waitingExecution.mode);
|
||||
expect(retrySuccessId).toBeNull();
|
||||
expect(retryOf).toBeNull();
|
||||
expect(startedAt).not.toBeNull();
|
||||
expect(stoppedAt).not.toBeNull();
|
||||
expect(workflowId).toBe(waitingExecution.workflowId);
|
||||
expect(new Date(waitTill).getTime()).toBeGreaterThan(Date.now() - 1000);
|
||||
});
|
||||
|
||||
test('GET /executions should retrieve all executions of specific workflow', async () => {
|
||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
|
||||
|
||||
const authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
auth: true,
|
||||
user: owner,
|
||||
version: 1,
|
||||
});
|
||||
|
||||
const [workflow, workflow2] = await testDb.createManyWorkflows(2, {}, owner);
|
||||
|
||||
const savedExecutions = await testDb.createManyExecutions(
|
||||
2,
|
||||
workflow,
|
||||
// @ts-ignore
|
||||
testDb.createSuccessfulExecution,
|
||||
);
|
||||
// @ts-ignore
|
||||
await testDb.createManyExecutions(2, workflow2, testDb.createSuccessfulExecution);
|
||||
|
||||
const response = await authOwnerAgent.get(`/executions`).query({
|
||||
workflowId: workflow.id,
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.body.data.length).toBe(2);
|
||||
expect(response.body.nextCursor).toBe(null);
|
||||
|
||||
for (const execution of response.body.data) {
|
||||
const {
|
||||
id,
|
||||
finished,
|
||||
@@ -474,16 +126,240 @@ test('GET /executions should retrieve all executions of specific workflow', asyn
|
||||
stoppedAt,
|
||||
workflowId,
|
||||
waitTill,
|
||||
} = execution;
|
||||
} = response.body;
|
||||
|
||||
expect(savedExecutions.some((exec) => exec.id === id)).toBe(true);
|
||||
expect(id).toBeDefined();
|
||||
expect(finished).toBe(true);
|
||||
expect(mode).toBeDefined();
|
||||
expect(mode).toEqual(execution.mode);
|
||||
expect(retrySuccessId).toBeNull();
|
||||
expect(retryOf).toBeNull();
|
||||
expect(startedAt).not.toBeNull();
|
||||
expect(stoppedAt).not.toBeNull();
|
||||
expect(workflowId).toBe(workflow.id);
|
||||
expect(workflowId).toBe(execution.workflowId);
|
||||
expect(waitTill).toBeNull();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /executions', () => {
|
||||
test('should fail due to missing API Key', testWithAPIKey('get', '/executions', null));
|
||||
|
||||
test('should fail due to invalid API Key', testWithAPIKey('get', '/executions', 'abcXYZ'));
|
||||
|
||||
test('should retrieve all successful executions', async () => {
|
||||
const workflow = await testDb.createWorkflow({}, owner);
|
||||
|
||||
const successfulExecution = await testDb.createSuccessfulExecution(workflow);
|
||||
|
||||
await testDb.createErrorExecution(workflow);
|
||||
|
||||
const response = await authOwnerAgent.get(`/executions`).query({
|
||||
status: 'success',
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.body.data.length).toBe(1);
|
||||
expect(response.body.nextCursor).toBe(null);
|
||||
|
||||
const {
|
||||
id,
|
||||
finished,
|
||||
mode,
|
||||
retryOf,
|
||||
retrySuccessId,
|
||||
startedAt,
|
||||
stoppedAt,
|
||||
workflowId,
|
||||
waitTill,
|
||||
} = response.body.data[0];
|
||||
|
||||
expect(id).toBeDefined();
|
||||
expect(finished).toBe(true);
|
||||
expect(mode).toEqual(successfulExecution.mode);
|
||||
expect(retrySuccessId).toBeNull();
|
||||
expect(retryOf).toBeNull();
|
||||
expect(startedAt).not.toBeNull();
|
||||
expect(stoppedAt).not.toBeNull();
|
||||
expect(workflowId).toBe(successfulExecution.workflowId);
|
||||
expect(waitTill).toBeNull();
|
||||
});
|
||||
|
||||
// failing on Postgres and MySQL - ref: https://github.com/n8n-io/n8n/pull/3834
|
||||
test.skip('should paginate two executions', async () => {
|
||||
const workflow = await testDb.createWorkflow({}, owner);
|
||||
|
||||
const firstSuccessfulExecution = await testDb.createSuccessfulExecution(workflow);
|
||||
|
||||
const secondSuccessfulExecution = await testDb.createSuccessfulExecution(workflow);
|
||||
|
||||
await testDb.createErrorExecution(workflow);
|
||||
|
||||
const firstExecutionResponse = await authOwnerAgent.get(`/executions`).query({
|
||||
status: 'success',
|
||||
limit: 1,
|
||||
});
|
||||
|
||||
expect(firstExecutionResponse.statusCode).toBe(200);
|
||||
expect(firstExecutionResponse.body.data.length).toBe(1);
|
||||
expect(firstExecutionResponse.body.nextCursor).toBeDefined();
|
||||
|
||||
const secondExecutionResponse = await authOwnerAgent.get(`/executions`).query({
|
||||
status: 'success',
|
||||
limit: 1,
|
||||
cursor: firstExecutionResponse.body.nextCursor,
|
||||
});
|
||||
|
||||
expect(secondExecutionResponse.statusCode).toBe(200);
|
||||
expect(secondExecutionResponse.body.data.length).toBe(1);
|
||||
expect(secondExecutionResponse.body.nextCursor).toBeNull();
|
||||
|
||||
const successfulExecutions = [firstSuccessfulExecution, secondSuccessfulExecution];
|
||||
const executions = [...firstExecutionResponse.body.data, ...secondExecutionResponse.body.data];
|
||||
|
||||
for (let i = 0; i < executions.length; i++) {
|
||||
const {
|
||||
id,
|
||||
finished,
|
||||
mode,
|
||||
retryOf,
|
||||
retrySuccessId,
|
||||
startedAt,
|
||||
stoppedAt,
|
||||
workflowId,
|
||||
waitTill,
|
||||
} = executions[i];
|
||||
|
||||
expect(id).toBeDefined();
|
||||
expect(finished).toBe(true);
|
||||
expect(mode).toEqual(successfulExecutions[i].mode);
|
||||
expect(retrySuccessId).toBeNull();
|
||||
expect(retryOf).toBeNull();
|
||||
expect(startedAt).not.toBeNull();
|
||||
expect(stoppedAt).not.toBeNull();
|
||||
expect(workflowId).toBe(successfulExecutions[i].workflowId);
|
||||
expect(waitTill).toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
test('should retrieve all error executions', async () => {
|
||||
const workflow = await testDb.createWorkflow({}, owner);
|
||||
|
||||
await testDb.createSuccessfulExecution(workflow);
|
||||
|
||||
const errorExecution = await testDb.createErrorExecution(workflow);
|
||||
|
||||
const response = await authOwnerAgent.get(`/executions`).query({
|
||||
status: 'error',
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.body.data.length).toBe(1);
|
||||
expect(response.body.nextCursor).toBe(null);
|
||||
|
||||
const {
|
||||
id,
|
||||
finished,
|
||||
mode,
|
||||
retryOf,
|
||||
retrySuccessId,
|
||||
startedAt,
|
||||
stoppedAt,
|
||||
workflowId,
|
||||
waitTill,
|
||||
} = response.body.data[0];
|
||||
|
||||
expect(id).toBeDefined();
|
||||
expect(finished).toBe(false);
|
||||
expect(mode).toEqual(errorExecution.mode);
|
||||
expect(retrySuccessId).toBeNull();
|
||||
expect(retryOf).toBeNull();
|
||||
expect(startedAt).not.toBeNull();
|
||||
expect(stoppedAt).not.toBeNull();
|
||||
expect(workflowId).toBe(errorExecution.workflowId);
|
||||
expect(waitTill).toBeNull();
|
||||
});
|
||||
|
||||
test('should return all waiting executions', async () => {
|
||||
const workflow = await testDb.createWorkflow({}, owner);
|
||||
|
||||
await testDb.createSuccessfulExecution(workflow);
|
||||
|
||||
await testDb.createErrorExecution(workflow);
|
||||
|
||||
const waitingExecution = await testDb.createWaitingExecution(workflow);
|
||||
|
||||
const response = await authOwnerAgent.get(`/executions`).query({
|
||||
status: 'waiting',
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.body.data.length).toBe(1);
|
||||
expect(response.body.nextCursor).toBe(null);
|
||||
|
||||
const {
|
||||
id,
|
||||
finished,
|
||||
mode,
|
||||
retryOf,
|
||||
retrySuccessId,
|
||||
startedAt,
|
||||
stoppedAt,
|
||||
workflowId,
|
||||
waitTill,
|
||||
} = response.body.data[0];
|
||||
|
||||
expect(id).toBeDefined();
|
||||
expect(finished).toBe(false);
|
||||
expect(mode).toEqual(waitingExecution.mode);
|
||||
expect(retrySuccessId).toBeNull();
|
||||
expect(retryOf).toBeNull();
|
||||
expect(startedAt).not.toBeNull();
|
||||
expect(stoppedAt).not.toBeNull();
|
||||
expect(workflowId).toBe(waitingExecution.workflowId);
|
||||
expect(new Date(waitTill).getTime()).toBeGreaterThan(Date.now() - 1000);
|
||||
});
|
||||
|
||||
test('should retrieve all executions of specific workflow', async () => {
|
||||
const [workflow, workflow2] = await testDb.createManyWorkflows(2, {}, owner);
|
||||
|
||||
const savedExecutions = await testDb.createManyExecutions(
|
||||
2,
|
||||
workflow,
|
||||
// @ts-ignore
|
||||
testDb.createSuccessfulExecution,
|
||||
);
|
||||
// @ts-ignore
|
||||
await testDb.createManyExecutions(2, workflow2, testDb.createSuccessfulExecution);
|
||||
|
||||
const response = await authOwnerAgent.get(`/executions`).query({
|
||||
workflowId: workflow.id,
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.body.data.length).toBe(2);
|
||||
expect(response.body.nextCursor).toBe(null);
|
||||
|
||||
for (const execution of response.body.data) {
|
||||
const {
|
||||
id,
|
||||
finished,
|
||||
mode,
|
||||
retryOf,
|
||||
retrySuccessId,
|
||||
startedAt,
|
||||
stoppedAt,
|
||||
workflowId,
|
||||
waitTill,
|
||||
} = execution;
|
||||
|
||||
expect(savedExecutions.some((exec) => exec.id === id)).toBe(true);
|
||||
expect(finished).toBe(true);
|
||||
expect(mode).toBeDefined();
|
||||
expect(retrySuccessId).toBeNull();
|
||||
expect(retryOf).toBeNull();
|
||||
expect(startedAt).not.toBeNull();
|
||||
expect(stoppedAt).not.toBeNull();
|
||||
expect(workflowId).toBe(workflow.id);
|
||||
expect(waitTill).toBeNull();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user