From 2d8421943fc09a61c234896d187660f433502be2 Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Sun, 15 Oct 2023 20:01:05 +0200 Subject: [PATCH] test: Implement tests for getConfig graphQL query --- .../src/graphql/queries/get-config.ee.test.ts | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 packages/backend/src/graphql/queries/get-config.ee.test.ts diff --git a/packages/backend/src/graphql/queries/get-config.ee.test.ts b/packages/backend/src/graphql/queries/get-config.ee.test.ts new file mode 100644 index 00000000..d31e3943 --- /dev/null +++ b/packages/backend/src/graphql/queries/get-config.ee.test.ts @@ -0,0 +1,96 @@ +import request from 'supertest'; +import app from '../../app'; +import createConfig from '../../../test/fixtures/config'; +import { IConfig } from '@automatisch/types'; +import * as license from '../../helpers/license.ee'; + +describe('graphQL getConfig query', () => { + let configOne: IConfig, + configTwo: IConfig, + configThree: IConfig, + query: string; + + beforeEach(async () => { + configOne = await createConfig({ key: 'configOne' }); + configTwo = await createConfig({ key: 'configTwo' }); + configThree = await createConfig({ key: 'configThree' }); + + query = ` + query { + getConfig + } + `; + }); + + describe('and without valid license', () => { + beforeEach(async () => { + jest.spyOn(license, 'hasValidLicense').mockResolvedValue(false); + }); + + describe('and correct permissions', () => { + it('should return empty config data', async () => { + const response = await request(app) + .post('/graphql') + .send({ query }) + .expect(200); + + const expectedResponsePayload = { data: { getConfig: {} } }; + + expect(response.body).toEqual(expectedResponsePayload); + }); + }); + }); + + describe('and with valid license', () => { + beforeEach(async () => { + jest.spyOn(license, 'hasValidLicense').mockResolvedValue(true); + }); + + describe('and without providing specific keys', () => { + it('should return all config data', async () => { + const response = await request(app) + .post('/graphql') + .send({ query }) + .expect(200); + + const expectedResponsePayload = { + data: { + getConfig: { + [configOne.key]: configOne.value.data, + [configTwo.key]: configTwo.value.data, + [configThree.key]: configThree.value.data, + }, + }, + }; + + expect(response.body).toEqual(expectedResponsePayload); + }); + }); + + describe('and with providing specific keys', () => { + it('should return all config data', async () => { + query = ` + query { + getConfig(keys: ["configOne", "configTwo"]) + } + `; + + const response = await request(app) + .post('/graphql') + .send({ query }) + .expect(200); + + const expectedResponsePayload = { + data: { + getConfig: { + [configOne.key]: configOne.value.data, + [configTwo.key]: configTwo.value.data, + }, + }, + }; + + expect(response.body).toEqual(expectedResponsePayload); + }); + }); + }); +});