From 1f8b81ee7849005df8a1d12e71b20f3e095dac73 Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Thu, 29 Feb 2024 18:03:27 +0000 Subject: [PATCH] refactor: remove GetAutomatischInfo GQL query --- .../graphql/queries/get-automatisch-info.js | 21 -- .../queries/get-automatisch-info.test.js | 190 ------------------ .../backend/src/graphql/query-resolvers.js | 2 - packages/backend/src/graphql/schema.graphql | 7 - .../backend/src/helpers/authentication.js | 1 - .../graphql/queries/get-automatisch-info.js | 9 - 6 files changed, 230 deletions(-) delete mode 100644 packages/backend/src/graphql/queries/get-automatisch-info.js delete mode 100644 packages/backend/src/graphql/queries/get-automatisch-info.test.js delete mode 100644 packages/web/src/graphql/queries/get-automatisch-info.js diff --git a/packages/backend/src/graphql/queries/get-automatisch-info.js b/packages/backend/src/graphql/queries/get-automatisch-info.js deleted file mode 100644 index 63d444a2..00000000 --- a/packages/backend/src/graphql/queries/get-automatisch-info.js +++ /dev/null @@ -1,21 +0,0 @@ -import appConfig from '../../config/app.js'; -import { getLicense } from '../../helpers/license.ee.js'; - -const getAutomatischInfo = async () => { - const license = await getLicense(); - - const computedLicense = { - id: license ? license.id : null, - name: license ? license.name : null, - expireAt: license ? license.expireAt : null, - verified: license ? true : false, - }; - - return { - isCloud: appConfig.isCloud, - isMation: appConfig.isMation, - license: computedLicense, - }; -}; - -export default getAutomatischInfo; diff --git a/packages/backend/src/graphql/queries/get-automatisch-info.test.js b/packages/backend/src/graphql/queries/get-automatisch-info.test.js deleted file mode 100644 index eaa5477a..00000000 --- a/packages/backend/src/graphql/queries/get-automatisch-info.test.js +++ /dev/null @@ -1,190 +0,0 @@ -import { vi, describe, it, expect, beforeEach } from 'vitest'; -import request from 'supertest'; -import app from '../../app'; -import * as license from '../../helpers/license.ee'; -import appConfig from '../../config/app'; - -describe('graphQL getAutomatischInfo query', () => { - const query = ` - query { - getAutomatischInfo { - isCloud - isMation - license { - id - name - expireAt - verified - } - } - } - `; - - describe('and without valid license', () => { - beforeEach(async () => { - vi.spyOn(license, 'getLicense').mockResolvedValue(false); - - vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(false); - vi.spyOn(appConfig, 'isMation', 'get').mockReturnValue(false); - }); - - it('should return empty license data', async () => { - const response = await request(app) - .post('/graphql') - .send({ query }) - .expect(200); - - const expectedResponsePayload = { - data: { - getAutomatischInfo: { - isCloud: false, - isMation: false, - license: { - id: null, - name: null, - expireAt: null, - verified: false, - }, - }, - }, - }; - - expect(response.body).toEqual(expectedResponsePayload); - }); - }); - - describe('and with valid license', () => { - beforeEach(async () => { - const mockedLicense = { - id: '123123', - name: 'Test License', - expireAt: '2025-08-09T10:56:54.144Z', - verified: true, - }; - - vi.spyOn(license, 'getLicense').mockResolvedValue(mockedLicense); - }); - - describe('and with cloud flag enabled', () => { - beforeEach(async () => { - vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(true); - }); - - it('should return all license data', async () => { - const response = await request(app) - .post('/graphql') - .send({ query }) - .expect(200); - - const expectedResponsePayload = { - data: { - getAutomatischInfo: { - isCloud: true, - isMation: false, - license: { - expireAt: '2025-08-09T10:56:54.144Z', - id: '123123', - name: 'Test License', - verified: true, - }, - }, - }, - }; - - expect(response.body).toEqual(expectedResponsePayload); - }); - }); - - describe('and with cloud flag disabled', () => { - beforeEach(async () => { - vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(false); - }); - - it('should return all license data', async () => { - const response = await request(app) - .post('/graphql') - .send({ query }) - .expect(200); - - const expectedResponsePayload = { - data: { - getAutomatischInfo: { - isCloud: false, - isMation: false, - license: { - expireAt: '2025-08-09T10:56:54.144Z', - id: '123123', - name: 'Test License', - verified: true, - }, - }, - }, - }; - - expect(response.body).toEqual(expectedResponsePayload); - }); - }); - - describe('and with mation flag enabled', () => { - beforeEach(async () => { - vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(false); - vi.spyOn(appConfig, 'isMation', 'get').mockReturnValue(true); - }); - - it('should return all license data', async () => { - const response = await request(app) - .post('/graphql') - .send({ query }) - .expect(200); - - const expectedResponsePayload = { - data: { - getAutomatischInfo: { - isCloud: false, - isMation: true, - license: { - expireAt: '2025-08-09T10:56:54.144Z', - id: '123123', - name: 'Test License', - verified: true, - }, - }, - }, - }; - - expect(response.body).toEqual(expectedResponsePayload); - }); - }); - - describe('and with mation flag disabled', () => { - beforeEach(async () => { - vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(false); - vi.spyOn(appConfig, 'isMation', 'get').mockReturnValue(false); - }); - - it('should return all license data', async () => { - const response = await request(app) - .post('/graphql') - .send({ query }) - .expect(200); - - const expectedResponsePayload = { - data: { - getAutomatischInfo: { - isMation: false, - isCloud: false, - license: { - expireAt: '2025-08-09T10:56:54.144Z', - id: '123123', - name: 'Test License', - verified: true, - }, - }, - }, - }; - - expect(response.body).toEqual(expectedResponsePayload); - }); - }); - }); -}); diff --git a/packages/backend/src/graphql/query-resolvers.js b/packages/backend/src/graphql/query-resolvers.js index f4bf2916..f4535809 100644 --- a/packages/backend/src/graphql/query-resolvers.js +++ b/packages/backend/src/graphql/query-resolvers.js @@ -3,7 +3,6 @@ import getAppAuthClient from './queries/get-app-auth-client.ee.js'; import getAppAuthClients from './queries/get-app-auth-clients.ee.js'; import getAppConfig from './queries/get-app-config.ee.js'; import getApps from './queries/get-apps.js'; -import getAutomatischInfo from './queries/get-automatisch-info.js'; import getBillingAndUsage from './queries/get-billing-and-usage.ee.js'; import getConfig from './queries/get-config.ee.js'; import getConnectedApps from './queries/get-connected-apps.js'; @@ -39,7 +38,6 @@ const queryResolvers = { getAppAuthClients, getAppConfig, getApps, - getAutomatischInfo, getBillingAndUsage, getConfig, getConnectedApps, diff --git a/packages/backend/src/graphql/schema.graphql b/packages/backend/src/graphql/schema.graphql index 895c9dc5..f244b2f0 100644 --- a/packages/backend/src/graphql/schema.graphql +++ b/packages/backend/src/graphql/schema.graphql @@ -40,7 +40,6 @@ type Query { key: String! parameters: JSONObject ): [SubstepArgument] - getAutomatischInfo: GetAutomatischInfo getBillingAndUsage: GetBillingAndUsage getCurrentUser: User getConfig(keys: [String]): JSONObject @@ -644,12 +643,6 @@ type AppHealth { version: String } -type GetAutomatischInfo { - isCloud: Boolean - isMation: Boolean - license: License -} - type License { id: String name: String diff --git a/packages/backend/src/helpers/authentication.js b/packages/backend/src/helpers/authentication.js index 42708a0b..8d24b657 100644 --- a/packages/backend/src/helpers/authentication.js +++ b/packages/backend/src/helpers/authentication.js @@ -42,7 +42,6 @@ const isAuthenticatedRule = rule()(isAuthenticated); export const authenticationRules = { Query: { '*': isAuthenticatedRule, - getAutomatischInfo: allow, getConfig: allow, getNotifications: allow, healthcheck: allow, diff --git a/packages/web/src/graphql/queries/get-automatisch-info.js b/packages/web/src/graphql/queries/get-automatisch-info.js deleted file mode 100644 index f8cd9b58..00000000 --- a/packages/web/src/graphql/queries/get-automatisch-info.js +++ /dev/null @@ -1,9 +0,0 @@ -import { gql } from '@apollo/client'; -export const GET_AUTOMATISCH_INFO = gql` - query GetAutomatischInfo { - getAutomatischInfo { - isCloud - isMation - } - } -`;