Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`DynamoDB module functions get 1`] = `
{
Expand Down
2 changes: 1 addition & 1 deletion __tests__/__snapshots__/resolvers.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`dynamodb resolvers something 1`] = `
{
Expand Down
10 changes: 8 additions & 2 deletions __tests__/helpers.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
"use strict";

import { fileURLToPath, pathToFileURL } from "url";
import { dirname, resolve } from "path";
import { AppSyncClient, EvaluateCodeCommand } from "@aws-sdk/client-appsync";
import { util } from "..";
import * as ddb from "../dynamodb";
import * as rds from "../rds";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const projectRoot = resolve(__dirname, "..");

let client = null;

const runResolverFunctionOnAWS = async (code, context, functionName) => {
Expand Down Expand Up @@ -65,8 +71,8 @@ export const checkResolverValid = async (code, context, functionName) => {
result = await runResolverFunctionOnAWS(fullCode, context, functionName);
} else {
const fullCode = `
import { util } from '..';
import * as rds from '../rds';
import { util } from '${pathToFileURL(resolve(projectRoot, "index.js"))}';
import * as rds from '${pathToFileURL(resolve(projectRoot, "rds/index.js"))}';
` + code;
const encodedJs = encodeURIComponent(fullCode);
const dataUri = 'data:text/javascript;charset=utf-8,' + encodedJs;
Expand Down
17 changes: 8 additions & 9 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,21 @@ describe("general utilities", () => {
});

describe("time utilities", () => {
afterEach(() => {
jest.useRealTimers();
});

test("nowFormatted", async () => {
// patch date utilities to ensure consistency
const newDate = new Date(2021, 1, 1);
const spied = jest.spyOn(global, 'Date').mockImplementation(() => newDate);
jest.useFakeTimers();
jest.setSystemTime(new Date(Date.UTC(2021, 1, 1)));

// TODO: not strictly correct, but close
expect(util.time.nowFormatted('YYYY-MM-dd HH:mm:ss')).toEqual("2021-02-01T00:00:00.000Z");
spied.mockRestore();
});
test("nowISO8601", async () => {
// patch date utilities to ensure consistency
const newDate = new Date(Date.UTC(2021, 1, 1));
const spied = jest.spyOn(global, 'Date').mockImplementation(() => newDate);
jest.useFakeTimers();
jest.setSystemTime(new Date(Date.UTC(2021, 1, 1)));

expect(util.time.nowISO8601()).toEqual("2021-02-01T00:00:00.000Z");
spied.mockRestore();
});
});

Expand Down