Skip to content

Instantly share code, notes, and snippets.

@brettski
Created December 3, 2020 17:11
Show Gist options
  • Save brettski/a12467c6cd2541e92bd3db9ca2b4bf16 to your computer and use it in GitHub Desktop.
Save brettski/a12467c6cd2541e92bd3db9ca2b4bf16 to your computer and use it in GitHub Desktop.
A test we don't need any longer which I wanted to retain for reference
const product = {
name: 'Our testing product',
description: 'a product object used for testing',
type: 'TICKET',
createdAt: '2020-11-20T15:03:35.219Z',
createdBy: 'auth0|0',
lastUpdatedAt: '2020-11-20T15:03:35.219Z',
lastUpdatedBy: 'auth0|0',
};
const copy = {
...product,
};
describe('productDateForge tests', () => {
let productDateForge;
const originalEnv = process.env;
beforeAll(() => {
jest.resetModules();
process.env = { ...originalEnv }; // puts a copy on process.env
// Required for @thatconference/api
process.env.INFLUX_TOKEN = 'TEST_INFLUX_TOKEN_VALUE';
process.env.INFLUX_ORG_ID = 'TEST_INFLUX_ORG_ID_VALUE';
process.env.INFLUX_BUCKET_ID = 'INFLUX_BUCKET_ID';
process.env.INFLUX_HOST = 'INFLUX_HOST';
productDateForge = require('../productDateForge').productDateForge;
});
afterAll(() => {
process.env = originalEnv;
});
describe('productDateForge should not mutate non-date fields', () => {
it('type, createdBy and lastUpdatedBy will remain the same', () => {
const forged = productDateForge(product);
expect(forged.type).toBe(copy.type);
expect(forged.createdBy).toBe(copy.createdBy);
expect(forged.lastUpdatedBy).toBe(copy.lastUpdatedBy);
});
it('string dates will return as Date types', () => {
const forged = productDateForge(product);
expect(forged.createdAt).toBeInstanceOf(Date);
expect(forged.lastUpdatedAt).toBeInstanceOf(Date);
});
it('string dates will be the correct date', () => {
const forged = productDateForge(product);
expect(forged.createdAt).toStrictEqual(new Date(copy.createdAt));
expect(forged.lastUpdatedAt).toStrictEqual(new Date(copy.lastUpdatedAt));
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment