Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrw committed Jan 31, 2024
1 parent 4210575 commit 6bf06fa
Show file tree
Hide file tree
Showing 7 changed files with 844 additions and 844 deletions.
102 changes: 51 additions & 51 deletions __tests__/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@ import * as rds from "../rds";
let client = null;

const runResolverFunctionOnAWS = async (code, context, functionName) => {
if (!client) {
client = new AppSyncClient();
}

if (!context) {
context = {};
}

const command = new EvaluateCodeCommand({
code,
context: JSON.stringify(context),
function: functionName,
runtime: {
name: "APPSYNC_JS",
runtimeVersion: "1.0.0",
},
});

const result = await client.send(command);
try {
return JSON.parse(result.evaluationResult);
} catch (e) {
console.error("invalid json", result);
}
if (!client) {
client = new AppSyncClient();
}

if (!context) {
context = {};
}

const command = new EvaluateCodeCommand({
code,
context: JSON.stringify(context),
function: functionName,
runtime: {
name: "APPSYNC_JS",
runtimeVersion: "1.0.0",
},
});

const result = await client.send(command);
try {
return JSON.parse(result.evaluationResult);
} catch (e) {
console.error("invalid json", result);
}
};

const runOnAWS = async (s, context) => {
const code = `
const code = `
import { util } from '@aws-appsync/utils';
import * as ddb from '@aws-appsync/utils/dynamodb';
import * as rds from '@aws-appsync/utils/rds';
Expand All @@ -48,50 +48,50 @@ const runOnAWS = async (s, context) => {
}
`;

return await runResolverFunctionOnAWS(code, context, "request");
return await runResolverFunctionOnAWS(code, context, "request");

}

export const checkResolverValid = async (code, context, functionName) => {
let result;
if (process.env.TEST_TARGET === "AWS_CLOUD") {
const fullCode = `
let result;
if (process.env.TEST_TARGET === "AWS_CLOUD") {
const fullCode = `
import { util } from '@aws-appsync/utils';
import * as rds from '@aws-appsync/utils/rds';
` + code;
result = await runResolverFunctionOnAWS(fullCode, context, functionName);
} else {
const fullCode = `
result = await runResolverFunctionOnAWS(fullCode, context, functionName);
} else {
const fullCode = `
import { util } from '..';
import * as rds from '../rds';
` + code;
const encodedJs = encodeURIComponent(fullCode);
const dataUri = 'data:text/javascript;charset=utf-8,' + encodedJs;
const module = await import(dataUri);
const encodedJs = encodeURIComponent(fullCode);
const dataUri = 'data:text/javascript;charset=utf-8,' + encodedJs;
const module = await import(dataUri);

const fn = module[functionName];
const fn = module[functionName];

transformContextForAppSync(context);
result = fn(context);
}
expect(result).toMatchSnapshot();
transformContextForAppSync(context);
result = fn(context);
}
expect(result).toMatchSnapshot();
};

// manipulate the context object to behave like the AppSync equivalent
function transformContextForAppSync(context) {
context.args = context.arguments;
context.args = context.arguments;
}

// If TEST_TARGET is AWS_CLOUD then run the check against AWS. Otherwise, run locally.
export const checkValid = async (s, context, postProcess) => {
let result;
if (process.env.TEST_TARGET === "AWS_CLOUD") {
result = await runOnAWS(s, context);
} else {
result = eval(s);
}
if (postProcess) {
result = postProcess(result);
}
expect(result).toMatchSnapshot();
let result;
if (process.env.TEST_TARGET === "AWS_CLOUD") {
result = await runOnAWS(s, context);
} else {
result = eval(s);
}
if (postProcess) {
result = postProcess(result);
}
expect(result).toMatchSnapshot();
}
Loading

0 comments on commit 6bf06fa

Please sign in to comment.