Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
appsync-template-tester
Advanced tools
Readme
Write unit tests for AWS AppSync VTL resolvers, with popular frameworks such as Jest.
yarn add appsync-template-tester --dev
import Parser from 'appsync-template-tester';
import { readFileSync } from 'fs';
import { join } from 'path';
// Load from a file (if not in a string already)
const templateFilePath = join(__dirname, './pathToFile.vtl');
const template = readFileSync(templateFilePath, {
encoding: 'utf8',
});
// Create the resolver
const parser = new Parser(template);
test('Test the resolver', () => {
// The Appsync Context (ctx) object
const context = {
// For example with a dynamoDB response resolver:
result: {
id: 'testId',
// ...
},
};
// parser.resolve() automatically typecasts
const response = parser.resolve(context);
// For convenience, the response is returned as a JS object rather than JSON
expect(response.id).toBe('testId');
});
This module supports all the provided core, map & time $util methods, and most of the dynamodb methods. The underlying methods can be seen in the Resolver Mapping Template Utility Reference docs.
Note: The errors list is also not returned (but $util.error will throw an error).
AWS AppSync provides extension methods via $extensions
, for example $extensions.evictFromApiCache
. It can be useful to assert that your VTL template is invoking these methods, therefore, you can provide custom extensions with your own implementations. Note that default extension methods are not provided. To read more about AWS AppSync extensions see the Extensions
docs.
// Create the parser with the mock extension function
const mockEvictFromApiCache = jest.fn();
const parser = new Parser(`$extensions.evictFromApiCache("Query", "users", {
"context.arguments.id": $context.arguments.id
})`);
parser.resolve({ arguments: { id: 10 } }, undefined, {
evictFromApiCache: mockEvictFromApiCache,
});
expect(mockEvictFromApiCache).toHaveBeenCalledTimes(1)
expect(mockEvictFromApiCache).toHaveBeenCalledWith("Query", "users", { "context.arguments.id": 10 })
FAQs
Unit test AppSync VTL resolvers, with popular frameworks such as Jest
The npm package appsync-template-tester receives a total of 942 weekly downloads. As such, appsync-template-tester popularity was classified as not popular.
We found that appsync-template-tester demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.