Nicolas Meienberger пре 2 година
родитељ
комит
c5b4a95abb

+ 4 - 0
.husky/commit-msg

@@ -0,0 +1,4 @@
+#!/bin/sh
+. "$(dirname "$0")/_/husky.sh"
+
+npx --no -- commitlint --edit $1

+ 3 - 0
commitlint.config.js

@@ -0,0 +1,3 @@
+module.exports = {
+  extends: ["@commitlint/config-conventional"],
+};

+ 12 - 2
package.json

@@ -5,6 +5,7 @@
   "scripts": {
     "test": "jest",
     "prepare": "husky install",
+    "commit": "git-cz",
     "act:test-install": "act --container-architecture linux/amd64 -j test-install",
     "act:docker": "act --container-architecture linux/amd64 --secret-file github.secrets -j build-images",
     "start:dev": "docker-compose -f docker-compose.dev.yml --env-file .env.dev up --build",
@@ -22,7 +23,11 @@
     "jest": "^28.1.0",
     "js-yaml": "^4.1.0",
     "ts-jest": "^28.0.2",
-    "typescript": "4.6.4"
+    "typescript": "4.6.4",
+    "@commitlint/cli": "^17.0.3",
+    "@commitlint/config-conventional": "^17.0.3",
+    "@commitlint/cz-commitlint": "^17.0.3",
+    "commitizen": "^4.2.4"
   },
   "repository": {
     "type": "git",
@@ -34,5 +39,10 @@
     "url": "https://github.com/meienberger/runtipi/issues"
   },
   "homepage": "https://github.com/meienberger/runtipi#readme",
-  "dependencies": {}
+  "dependencies": {},
+  "config": {
+    "commitizen": {
+      "path": "@commitlint/cz-commitlint"
+    }
+  }
 }

+ 3 - 0
packages/system-api/jest.config.cjs

@@ -8,4 +8,7 @@ module.exports = {
   collectCoverage: true,
   collectCoverageFrom: ['src/**/*.{ts,tsx}'],
   passWithNoTests: true,
+  transform: {
+    '^.+\\.graphql$': 'graphql-import-node/jest',
+  },
 };

+ 1 - 0
packages/system-api/package.json

@@ -79,6 +79,7 @@
     "eslint-config-prettier": "^8.5.0",
     "eslint-plugin-import": "^2.26.0",
     "eslint-plugin-prettier": "^4.0.0",
+    "graphql-import-node": "^0.0.5",
     "jest": "^28.1.0",
     "nodemon": "^2.0.15",
     "prettier": "2.6.2",

+ 54 - 0
packages/system-api/src/modules/apps/__tests__/apps.resolver.test.ts

@@ -0,0 +1,54 @@
+import { DataSource } from 'typeorm';
+import { setupConnection, teardownConnection } from '../../../test/connection';
+import fs from 'fs';
+import { gcall } from '../../../test/gcall';
+import App from '../app.entity';
+import { listAppInfosQuery } from '../../../test/queries';
+import { createApp } from './apps.factory';
+import { AppInfo, ListAppsResonse } from '../apps.types';
+
+jest.mock('fs');
+
+let db: DataSource | null = null;
+const TEST_SUITE = 'appsresolver';
+
+beforeAll(async () => {
+  db = await setupConnection(TEST_SUITE);
+});
+
+afterAll(async () => {
+  await db?.destroy();
+  await teardownConnection(TEST_SUITE);
+});
+
+beforeEach(async () => {
+  jest.resetModules();
+  jest.resetAllMocks();
+  jest.restoreAllMocks();
+  await App.clear();
+});
+
+describe('ListAppsInfos', () => {
+  let app1: AppInfo;
+
+  beforeEach(async () => {
+    const { MockFiles, appInfo } = await createApp();
+    app1 = appInfo;
+    // @ts-ignore
+    fs.__createMockFiles(MockFiles);
+  });
+
+  it('Can list apps', async () => {
+    const { data } = await gcall<{ listAppsInfo: ListAppsResonse }>({ source: listAppInfosQuery });
+
+    expect(data?.listAppsInfo.apps.length).toBe(1);
+    expect(data?.listAppsInfo.total).toBe(1);
+
+    const app = data?.listAppsInfo.apps[0];
+
+    expect(app?.id).toBe(app1.id);
+    expect(app?.author).toBe(app1.author);
+    expect(app?.name).toBe(app1.name);
+    expect(app?.available).toBe(app1.available);
+  });
+});

+ 26 - 0
packages/system-api/src/test/gcall.ts

@@ -0,0 +1,26 @@
+import { ExecutionResult, graphql, GraphQLSchema } from 'graphql';
+import { Maybe } from 'type-graphql';
+import { createSchema } from '../schema';
+
+interface Options {
+  source: string;
+  variableValues?: Maybe<{
+    [key: string]: any;
+  }>;
+  userId?: number;
+}
+
+let schema: GraphQLSchema | null = null;
+
+export const gcall = async <T>({ source, variableValues, userId }: Options): Promise<ExecutionResult<T, { [key: string]: any }>> => {
+  if (!schema) {
+    schema = await createSchema();
+  }
+
+  return graphql({
+    schema,
+    source,
+    variableValues,
+    contextValue: { req: { session: { userId } } },
+  }) as any;
+};

+ 7 - 0
packages/system-api/src/test/queries/index.ts

@@ -0,0 +1,7 @@
+/* eslint-disable import/no-extraneous-dependencies */
+import 'graphql-import-node';
+import { print } from 'graphql/language/printer';
+
+import * as listAppInfos from './listAppInfos.graphql';
+
+export const listAppInfosQuery = print(listAppInfos);

+ 24 - 0
packages/system-api/src/test/queries/listAppInfos.graphql

@@ -0,0 +1,24 @@
+query {
+  listAppsInfo {
+    apps {
+      id
+      available
+      port
+      name
+      description
+      version
+      author
+      source
+      categories
+      url_suffix
+      form_fields {
+        max
+        min
+        required
+        env_variable
+      }
+      requirements
+    }
+    total
+  }
+}

Разлика између датотеке није приказан због своје велике величине
+ 580 - 17
pnpm-lock.yaml


Неке датотеке нису приказане због велике количине промена