Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: remove e2e #8

Merged
merged 3 commits into from
Nov 15, 2023
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
62 changes: 33 additions & 29 deletions test/core.int.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import Supergood from '../src';
import { postEvents, postError } from '../src/api';
import { initialize } from './json-server-config';
import { errors } from '../src/constants';
import { request } from 'undici';
import { ErrorPayloadType, EventRequestType } from '../src/types';
import initialDB from './initial-db';
import http from 'http';
import fs from 'fs';
import path from 'path';
import get from 'lodash.get';

// HTTP libraries
import { request } from 'undici';
import superagent from 'superagent';
import axios from 'axios';
import fetch from 'node-fetch';

import Supergood from '../src';
import { postEvents, postError } from '../src/api';
import { initialize } from './json-server-config';
import { errors } from '../src/constants';
import { ErrorPayloadType, EventRequestType } from '../src/types';
import initialDB from './initial-db';

import { sleep } from '../src/utils';

const base64Regex =
Expand All @@ -40,7 +42,19 @@ const defaultConfig = {

let server: http.Server;

beforeAll(async () => {
const getEvents = (mockedPostEvents: jest.Mock): Array<EventRequestType> => {
return Object.values(
mockedPostEvents.mock.calls.flat()[1] as EventRequestType
);
};

const getErrors = (mockedPostError: jest.Mock): ErrorPayloadType => {
return Object.values(
mockedPostError.mock.calls.flat()
)[1] as ErrorPayloadType;
};

const resetDatabase = () => {
fs.writeFileSync(
path.join(__dirname, 'db.json'),
JSON.stringify(initialDB, null, 2),
Expand All @@ -49,33 +63,21 @@ beforeAll(async () => {
flag: 'w'
}
);
};

beforeAll(async () => {
resetDatabase();
server = await initialize();
});

afterAll(async () => {
server.close();
fs.writeFileSync(
path.join(__dirname, 'db.json'),
JSON.stringify(initialDB, null, 2),
{
encoding: 'utf8',
flag: 'w'
}
);
resetDatabase();
});

const getEvents = (mockedPostEvents: jest.Mock): Array<EventRequestType> =>
Object.values(mockedPostEvents.mock.calls.flat()[1] as EventRequestType);

const getErrors = (mockedPostError: jest.Mock): ErrorPayloadType => {
return Object.values(
mockedPostError.mock.calls.flat()
)[1] as ErrorPayloadType;
};

jest.mock('../src/api', () => ({
postEvents: jest.fn(async (eventSinkUrl, data) => ({ data })),
postError: jest.fn(async (errorSinkUrl, payload) => ({
postEvents: jest.fn(async (_, data) => ({ data })),
postError: jest.fn(async (_, payload) => ({
payload
}))
}));
Expand Down Expand Up @@ -171,7 +173,7 @@ describe('testing failure states', () => {
await axios.get(`${HTTP_OUTBOUND_TEST_SERVER}/posts`);
await Supergood.close();
const postedErrors = getErrors(postError as jest.Mock);
expect(postError as jest.Mock).toBeCalled();
expect(postError as jest.Mock).toHaveBeenCalled();
expect(postedErrors.message).toEqual(errors.POSTING_EVENTS);
});
});
Expand Down Expand Up @@ -498,7 +500,9 @@ describe('local client id and secret', () => {
});
});

xdescribe('testing openAI', () => {
// node 14 fails due to AbortController not being supported
// need to figure out why it is not get caught by the agent
describe.skip('testing openAI', () => {
test('simple chat completion call being logged', async () => {
/* eslint-disable-next-line @typescript-eslint/no-var-requires */
const OpenAI = require('openai');
Expand Down
31 changes: 0 additions & 31 deletions test/endToEnd.int.test.ts

This file was deleted.