|
@@ -8,7 +8,8 @@ import { createApp } from './apps.factory';
|
|
|
import { AppInfo, AppStatusEnum, ListAppsResonse } from '../apps.types';
|
|
|
import { createUser } from '../../auth/__tests__/user.factory';
|
|
|
import User from '../../auth/user.entity';
|
|
|
-import { installAppMutation } from '../../../test/mutations';
|
|
|
+import { installAppMutation, startAppMutation, stopAppMutation, uninstallAppMutation, updateAppConfigMutation, updateAppMutation } from '../../../test/mutations';
|
|
|
+import { faker } from '@faker-js/faker';
|
|
|
|
|
|
jest.mock('fs');
|
|
|
jest.mock('child_process');
|
|
@@ -235,3 +236,295 @@ describe('InstallApp', () => {
|
|
|
expect(data?.installApp).toBeUndefined();
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+describe('StartApp', () => {
|
|
|
+ let app1: AppInfo;
|
|
|
+
|
|
|
+ beforeEach(async () => {
|
|
|
+ const app1create = await createApp({ status: AppStatusEnum.STOPPED, installed: true });
|
|
|
+ app1 = app1create.appInfo;
|
|
|
+ // @ts-ignore
|
|
|
+ fs.__createMockFiles(app1create.MockFiles);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('Can start app', async () => {
|
|
|
+ const user = await createUser();
|
|
|
+
|
|
|
+ const { data } = await gcall<{ startApp: TApp }>({
|
|
|
+ source: startAppMutation,
|
|
|
+ userId: user.id,
|
|
|
+ variableValues: { id: app1.id },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(data?.startApp.info.id).toBe(app1.id);
|
|
|
+ expect(data?.startApp.status).toBe(AppStatusEnum.RUNNING.toUpperCase());
|
|
|
+ });
|
|
|
+
|
|
|
+ it("Should return an error if app doesn't exist", async () => {
|
|
|
+ const user = await createUser();
|
|
|
+
|
|
|
+ const { data, errors } = await gcall<{ startApp: TApp }>({
|
|
|
+ source: startAppMutation,
|
|
|
+ userId: user.id,
|
|
|
+ variableValues: { id: 'not-existing' },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(errors?.[0].message).toBe('App not-existing not found');
|
|
|
+ expect(data?.startApp).toBeUndefined();
|
|
|
+ });
|
|
|
+
|
|
|
+ it("Should throw an error if user doesn't exist", async () => {
|
|
|
+ const { data, errors } = await gcall<{ startApp: TApp }>({
|
|
|
+ source: startAppMutation,
|
|
|
+ userId: 0,
|
|
|
+ variableValues: { id: app1.id },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(errors?.[0].message).toBe('Access denied! You need to be authorized to perform this action!');
|
|
|
+ expect(data?.startApp).toBeUndefined();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('Should throw an error if no userId is provided', async () => {
|
|
|
+ const { data, errors } = await gcall<{ startApp: TApp }>({
|
|
|
+ source: startAppMutation,
|
|
|
+ variableValues: { id: app1.id },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(errors?.[0].message).toBe('Access denied! You need to be authorized to perform this action!');
|
|
|
+ expect(data?.startApp).toBeUndefined();
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
+describe('StopApp', () => {
|
|
|
+ let app1: AppInfo;
|
|
|
+
|
|
|
+ beforeEach(async () => {
|
|
|
+ const app1create = await createApp({ status: AppStatusEnum.RUNNING, installed: true });
|
|
|
+ app1 = app1create.appInfo;
|
|
|
+ // @ts-ignore
|
|
|
+ fs.__createMockFiles(app1create.MockFiles);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('Can stop app', async () => {
|
|
|
+ const user = await createUser();
|
|
|
+
|
|
|
+ const { data } = await gcall<{ stopApp: TApp }>({
|
|
|
+ source: stopAppMutation,
|
|
|
+ userId: user.id,
|
|
|
+ variableValues: { id: app1.id },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(data?.stopApp.info.id).toBe(app1.id);
|
|
|
+ expect(data?.stopApp.status).toBe(AppStatusEnum.STOPPED.toUpperCase());
|
|
|
+ });
|
|
|
+
|
|
|
+ it("Should return an error if app doesn't exist", async () => {
|
|
|
+ const user = await createUser();
|
|
|
+
|
|
|
+ const { data, errors } = await gcall<{ stopApp: TApp }>({
|
|
|
+ source: stopAppMutation,
|
|
|
+ userId: user.id,
|
|
|
+ variableValues: { id: 'not-existing' },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(errors?.[0].message).toBe('App not-existing not found');
|
|
|
+ expect(data?.stopApp).toBeUndefined();
|
|
|
+ });
|
|
|
+
|
|
|
+ it("Should throw an error if user doesn't exist", async () => {
|
|
|
+ const { data, errors } = await gcall<{ stopApp: TApp }>({
|
|
|
+ source: stopAppMutation,
|
|
|
+ userId: 0,
|
|
|
+ variableValues: { id: app1.id },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(errors?.[0].message).toBe('Access denied! You need to be authorized to perform this action!');
|
|
|
+ expect(data?.stopApp).toBeUndefined();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('Should throw an error if no userId is provided', async () => {
|
|
|
+ const { data, errors } = await gcall<{ stopApp: TApp }>({
|
|
|
+ source: stopAppMutation,
|
|
|
+ variableValues: { id: app1.id },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(errors?.[0].message).toBe('Access denied! You need to be authorized to perform this action!');
|
|
|
+ expect(data?.stopApp).toBeUndefined();
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
+describe('UninstallApp', () => {
|
|
|
+ let app1: AppInfo;
|
|
|
+
|
|
|
+ beforeEach(async () => {
|
|
|
+ const app1create = await createApp({ status: AppStatusEnum.STOPPED, installed: true });
|
|
|
+ app1 = app1create.appInfo;
|
|
|
+ // @ts-ignore
|
|
|
+ fs.__createMockFiles(app1create.MockFiles);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('Should uninstall app', async () => {
|
|
|
+ const user = await createUser();
|
|
|
+
|
|
|
+ const { data } = await gcall<{ uninstallApp: TApp }>({
|
|
|
+ source: uninstallAppMutation,
|
|
|
+ userId: user.id,
|
|
|
+ variableValues: { id: app1.id },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(data?.uninstallApp.info.id).toBe(app1.id);
|
|
|
+ expect(data?.uninstallApp.status).toBe(AppStatusEnum.MISSING.toUpperCase());
|
|
|
+ });
|
|
|
+
|
|
|
+ it("Should return an error if app doesn't exist", async () => {
|
|
|
+ const user = await createUser();
|
|
|
+
|
|
|
+ const { data, errors } = await gcall<{ uninstallApp: TApp }>({
|
|
|
+ source: uninstallAppMutation,
|
|
|
+ userId: user.id,
|
|
|
+ variableValues: { id: 'not-existing' },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(errors?.[0].message).toBe('App not-existing not found');
|
|
|
+ expect(data?.uninstallApp).toBeUndefined();
|
|
|
+ });
|
|
|
+
|
|
|
+ it("Should throw an error if user doesn't exist", async () => {
|
|
|
+ const { data, errors } = await gcall<{ uninstallApp: TApp }>({
|
|
|
+ source: uninstallAppMutation,
|
|
|
+ userId: 0,
|
|
|
+ variableValues: { id: app1.id },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(errors?.[0].message).toBe('Access denied! You need to be authorized to perform this action!');
|
|
|
+ expect(data?.uninstallApp).toBeUndefined();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('Should throw an error if no userId is provided', async () => {
|
|
|
+ const { data, errors } = await gcall<{ uninstallApp: TApp }>({
|
|
|
+ source: uninstallAppMutation,
|
|
|
+ variableValues: { id: app1.id },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(errors?.[0].message).toBe('Access denied! You need to be authorized to perform this action!');
|
|
|
+ expect(data?.uninstallApp).toBeUndefined();
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
+describe('UpdateAppConfig', () => {
|
|
|
+ let app1: AppInfo;
|
|
|
+
|
|
|
+ beforeEach(async () => {
|
|
|
+ const app1create = await createApp({ status: AppStatusEnum.STOPPED, installed: true });
|
|
|
+ app1 = app1create.appInfo;
|
|
|
+ // @ts-ignore
|
|
|
+ fs.__createMockFiles(app1create.MockFiles);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('Should update app config', async () => {
|
|
|
+ const user = await createUser();
|
|
|
+
|
|
|
+ const word = faker.random.word();
|
|
|
+
|
|
|
+ const { data } = await gcall<{ updateAppConfig: TApp }>({
|
|
|
+ source: updateAppConfigMutation,
|
|
|
+ userId: user.id,
|
|
|
+ variableValues: { input: { id: app1.id, form: { TEST_FIELD: word } } },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(data?.updateAppConfig.info.id).toBe(app1.id);
|
|
|
+ expect(data?.updateAppConfig.config.TEST_FIELD).toBe(word);
|
|
|
+ });
|
|
|
+
|
|
|
+ it("Should return an error if app doesn't exist", async () => {
|
|
|
+ const user = await createUser();
|
|
|
+
|
|
|
+ const { data, errors } = await gcall<{ updateAppConfig: TApp }>({
|
|
|
+ source: updateAppConfigMutation,
|
|
|
+ userId: user.id,
|
|
|
+ variableValues: { input: { id: 'not-existing', form: { TEST_FIELD: faker.random.word() } } },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(errors?.[0].message).toBe('App not-existing not found');
|
|
|
+ expect(data?.updateAppConfig).toBeUndefined();
|
|
|
+ });
|
|
|
+
|
|
|
+ it("Should throw an error if user doesn't exist", async () => {
|
|
|
+ const { data, errors } = await gcall<{ updateAppConfig: TApp }>({
|
|
|
+ source: updateAppConfigMutation,
|
|
|
+ userId: 0,
|
|
|
+ variableValues: { input: { id: app1.id, form: { TEST_FIELD: faker.random.word() } } },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(errors?.[0].message).toBe('Access denied! You need to be authorized to perform this action!');
|
|
|
+ expect(data?.updateAppConfig).toBeUndefined();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('Should throw an error if no userId is provided', async () => {
|
|
|
+ const { data, errors } = await gcall<{ updateAppConfig: TApp }>({
|
|
|
+ source: updateAppConfigMutation,
|
|
|
+ variableValues: { input: { id: app1.id, form: { TEST_FIELD: faker.random.word() } } },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(errors?.[0].message).toBe('Access denied! You need to be authorized to perform this action!');
|
|
|
+ expect(data?.updateAppConfig).toBeUndefined();
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
+describe('UpdateApp', () => {
|
|
|
+ let app1: AppInfo;
|
|
|
+
|
|
|
+ beforeEach(async () => {
|
|
|
+ const app1create = await createApp({ status: AppStatusEnum.STOPPED, installed: true });
|
|
|
+ app1 = app1create.appInfo;
|
|
|
+ // @ts-ignore
|
|
|
+ fs.__createMockFiles(app1create.MockFiles);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('Should update app', async () => {
|
|
|
+ const user = await createUser();
|
|
|
+
|
|
|
+ const { data } = await gcall<{ updateApp: TApp }>({
|
|
|
+ source: updateAppMutation,
|
|
|
+ userId: user.id,
|
|
|
+ variableValues: { id: app1.id },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(data?.updateApp.info.id).toBe(app1.id);
|
|
|
+ expect(data?.updateApp.info.name).toBe(data?.updateApp.info.name);
|
|
|
+ });
|
|
|
+
|
|
|
+ it("Should return an error if app doesn't exist", async () => {
|
|
|
+ const user = await createUser();
|
|
|
+
|
|
|
+ const { data, errors } = await gcall<{ updateApp: TApp }>({
|
|
|
+ source: updateAppMutation,
|
|
|
+ userId: user.id,
|
|
|
+ variableValues: { id: 'not-existing' },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(errors?.[0].message).toBe('App not-existing not found');
|
|
|
+ expect(data?.updateApp).toBeUndefined();
|
|
|
+ });
|
|
|
+
|
|
|
+ it("Should throw an error if user doesn't exist", async () => {
|
|
|
+ const { data, errors } = await gcall<{ updateApp: TApp }>({
|
|
|
+ source: updateAppMutation,
|
|
|
+ userId: 0,
|
|
|
+ variableValues: { id: app1.id },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(errors?.[0].message).toBe('Access denied! You need to be authorized to perform this action!');
|
|
|
+ expect(data?.updateApp).toBeUndefined();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('Should throw an error if no userId is provided', async () => {
|
|
|
+ const { data, errors } = await gcall<{ updateApp: TApp }>({
|
|
|
+ source: updateAppMutation,
|
|
|
+ variableValues: { id: app1.id },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(errors?.[0].message).toBe('Access denied! You need to be authorized to perform this action!');
|
|
|
+ expect(data?.updateApp).toBeUndefined();
|
|
|
+ });
|
|
|
+});
|