Skip to content

Commit

Permalink
Merge pull request #375 from lenneTech/develop
Browse files Browse the repository at this point in the history
Release 10.4.1
  • Loading branch information
kaihaase authored Oct 6, 2024
2 parents 30c9d10 + 7e0741c commit c920a67
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lenne.tech/nest-server",
"version": "10.4.0",
"version": "10.4.1",
"description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
"keywords": [
"node",
Expand Down
2 changes: 1 addition & 1 deletion spectaql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ servers:
info:
title: lT Nest Server
description: Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).
version: 10.3.4
version: 10.4.1
contact:
name: lenne.Tech GmbH
url: https://lenne.tech
Expand Down
33 changes: 28 additions & 5 deletions src/test/test.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,19 @@ export class TestHelper {

// Init
let query = '';
let name: string = undefined;

// Convert string to TestGraphQLConfig
if ((typeof graphql === 'string' || graphql instanceof String) && /^[a-zA-Z]+$/.test(graphql as string)) {
if (
(typeof graphql === 'string' || graphql instanceof String)
&& /^(?![a-zA-Z]+$).*$/.test((graphql as string).trim())
) {
// Use input as query
query = graphql as string;
query = (graphql as string).trim();
} else {
// Use input as name
if (typeof graphql === 'string' || graphql instanceof String) {
graphql = { name: graphql } as any;
graphql = { name: (graphql as string).trim() } as any;
}

// Prepare config
Expand All @@ -225,6 +229,7 @@ export class TestHelper {
},
graphql,
) as TestGraphQLConfig;
name = graphql.name;

// Init request
const queryObj = {};
Expand All @@ -248,7 +253,11 @@ export class TestHelper {
}

// Create request payload query
query = jsonToGraphQLQuery(queryObj, { pretty: true });
if (!graphql.fields?.length && !graphql.arguments) {
query = `${graphql.type} { ${graphql.name} }`;
} else {
query = jsonToGraphQLQuery(queryObj, { pretty: true });
}
}

if ((graphql as TestGraphQLConfig).type === TestGraphQLType.SUBSCRIPTION) {
Expand Down Expand Up @@ -298,7 +307,21 @@ export class TestHelper {
expect(response.headers['content-type']).toMatch('application/json');

// return data
return response.body.data ? response.body.data[(graphql as TestGraphQLConfig).name] : response.body;
if (response.body) {
if (response.body.data) {
return name ? response.body.data[(graphql as TestGraphQLConfig).name] : response.body.data;
}
return response.body;
}
if (response.text) {
if (JSON.parse(response.text).data) {
return name
? JSON.parse(response.text).data[(graphql as TestGraphQLConfig).name]
: JSON.parse(response.text).data;
}
return JSON.parse(response.text);
}
return undefined;
}

/**
Expand Down

0 comments on commit c920a67

Please sign in to comment.