Skip to content

Commit

Permalink
Merge pull request #369 from lenneTech/develop
Browse files Browse the repository at this point in the history
Release 10.3.3 (optimized)
  • Loading branch information
kaihaase authored Aug 22, 2024
2 parents 9ea687e + 835984a commit 3b67294
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
11 changes: 10 additions & 1 deletion src/test/test.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export interface TestGraphQLOptions {
*/
export interface TestRestOptions {
attachments?: Record<string, string>;
headers?: Record<string, string>;
log?: boolean;
logError?: boolean;
method?: 'DELETE' | 'GET' | 'PATCH' | 'POST' | 'PUT';
Expand Down Expand Up @@ -320,6 +321,7 @@ export class TestHelper {

// Request configuration
const requestConfig: any = {
headers: config.headers,
method: config.method,
url,
};
Expand Down Expand Up @@ -435,7 +437,7 @@ export class TestHelper {
): Promise<any> {
// Token
if (token) {
requestConfig.headers = { authorization: `Bearer ${token}` };
requestConfig.headers = { authorization: `Bearer ${token}`, ...(requestConfig.headers || {}) };
}

// Init response
Expand Down Expand Up @@ -465,6 +467,13 @@ export class TestHelper {
request.set('Authorization', `bearer ${token}`);
}

// Headers
if (requestConfig.headers) {
for (const [key, value] of Object.entries(requestConfig.headers)) {
request.set(key, value);
}
}

// Process variables (incl. attachments for GraphQL)
if (variables) {
request = this.processVariables(request, variables, (requestConfig.payload as any)?.query);
Expand Down
30 changes: 11 additions & 19 deletions tests/server.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,28 +109,16 @@ describe('ServerModule (e2e)', () => {
* Get Schema
*/
it('get schema', async () => {
const result = await fetch(`http://127.0.0.1:${port}/graphql`, {
body: '{"operationName":"IntrospectionQuery","variables":{},"query":"query IntrospectionQuery {\\n __schema {\\n queryType {\\n name\\n }\\n mutationType {\\n name\\n }\\n subscriptionType {\\n name\\n }\\n types {\\n ...FullType\\n }\\n directives {\\n name\\n description\\n locations\\n args {\\n ...InputValue\\n }\\n }\\n }\\n}\\n\\nfragment FullType on __Type {\\n kind\\n name\\n description\\n fields(includeDeprecated: true) {\\n name\\n description\\n args {\\n ...InputValue\\n }\\n type {\\n ...TypeRef\\n }\\n isDeprecated\\n deprecationReason\\n }\\n inputFields {\\n ...InputValue\\n }\\n interfaces {\\n ...TypeRef\\n }\\n enumValues(includeDeprecated: true) {\\n name\\n description\\n isDeprecated\\n deprecationReason\\n }\\n possibleTypes {\\n ...TypeRef\\n }\\n}\\n\\nfragment InputValue on __InputValue {\\n name\\n description\\n type {\\n ...TypeRef\\n }\\n defaultValue\\n}\\n\\nfragment TypeRef on __Type {\\n kind\\n name\\n ofType {\\n kind\\n name\\n ofType {\\n kind\\n name\\n ofType {\\n kind\\n name\\n ofType {\\n kind\\n name\\n ofType {\\n kind\\n name\\n ofType {\\n kind\\n name\\n ofType {\\n kind\\n name\\n }\\n }\\n }\\n }\\n }\\n }\\n }\\n}\\n"}',
const res: any = await testHelper.rest('/graphql', {
headers: {
'Referer': `http://localhost:${port}/`,
'Referrer-Policy': 'strict-origin-when-cross-origin',
'accept': '*/*',
'accept-language': 'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7',
'apollo-query-plan-experimental': '1',
'cache-control': 'no-cache',
'content-type': 'application/json',
'pragma': 'no-cache',
'sec-ch-ua': '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"macOS"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'cross-site',
'x-apollo-tracing': '1',
'x-apollo-operation-name': 'IntrospectionQuery',
},
method: 'POST',
payload:
'{"operationName":"IntrospectionQuery","variables":{},"query":"query IntrospectionQuery {\\n __schema {\\n queryType {\\n name\\n }\\n mutationType {\\n name\\n }\\n subscriptionType {\\n name\\n }\\n types {\\n ...FullType\\n }\\n directives {\\n name\\n description\\n locations\\n args {\\n ...InputValue\\n }\\n }\\n }\\n}\\n\\nfragment FullType on __Type {\\n kind\\n name\\n description\\n fields(includeDeprecated: true) {\\n name\\n description\\n args {\\n ...InputValue\\n }\\n type {\\n ...TypeRef\\n }\\n isDeprecated\\n deprecationReason\\n }\\n inputFields {\\n ...InputValue\\n }\\n interfaces {\\n ...TypeRef\\n }\\n enumValues(includeDeprecated: true) {\\n name\\n description\\n isDeprecated\\n deprecationReason\\n }\\n possibleTypes {\\n ...TypeRef\\n }\\n}\\n\\nfragment InputValue on __InputValue {\\n name\\n description\\n type {\\n ...TypeRef\\n }\\n defaultValue\\n}\\n\\nfragment TypeRef on __Type {\\n kind\\n name\\n ofType {\\n kind\\n name\\n ofType {\\n kind\\n name\\n ofType {\\n kind\\n name\\n ofType {\\n kind\\n name\\n ofType {\\n kind\\n name\\n ofType {\\n kind\\n name\\n ofType {\\n kind\\n name\\n }\\n }\\n }\\n }\\n }\\n }\\n }\\n}\\n"}',
});
expect(result.status).toEqual(200);
expect(res.data.__schema.queryType.name).toEqual('Query');
});

/**
Expand Down Expand Up @@ -334,7 +322,9 @@ describe('ServerModule (e2e)', () => {
if (envConfig.jwt.sameTokenIdPeriod) {
const timeBetween = Date.now() - gLastRefreshRequestTime;
console.debug(
`tempToken used | config: ${envConfig.jwt.sameTokenIdPeriod}, timeBetween: ${timeBetween}, rest: ${envConfig.jwt.sameTokenIdPeriod - timeBetween}`,
`tempToken used | config: ${envConfig.jwt.sameTokenIdPeriod}, timeBetween: ${timeBetween}, rest: ${
envConfig.jwt.sameTokenIdPeriod - timeBetween
}`,
);
expect(gLastRefreshRequestTime).toBeGreaterThanOrEqual(Date.now() - envConfig.jwt.sameTokenIdPeriod);
expect(testHelper.parseJwt(res.token).tokenId).toEqual(testHelper.parseJwt(gToken).tokenId);
Expand Down Expand Up @@ -371,7 +361,9 @@ describe('ServerModule (e2e)', () => {
if (sameTokenIdPeriod) {
const timeBetween = Date.now() - gLastRefreshRequestTime;
console.debug(
`tempToken2 used | config: ${sameTokenIdPeriod}, timeBetween: ${timeBetween}, rest: ${sameTokenIdPeriod - timeBetween}`,
`tempToken2 used | config: ${sameTokenIdPeriod}, timeBetween: ${timeBetween}, rest: ${
sameTokenIdPeriod - timeBetween
}`,
);
expect(testHelper.parseJwt(res.token).tokenId).toEqual(testHelper.parseJwt(gToken).tokenId);
} else {
Expand Down

0 comments on commit 3b67294

Please sign in to comment.