Skip to content

Commit

Permalink
feat(dtfs2-6892): fix issue due to unit test and e2e tests running on…
Browse files Browse the repository at this point in the history
… jsdom
  • Loading branch information
AlexBramhill committed Feb 12, 2025
1 parent 8552633 commit 5f3b106
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 14 deletions.
2 changes: 2 additions & 0 deletions libs/common/src/schemas/portal-user.schema.create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import z from 'zod';
import { generatePortalUserAuditDatabaseRecord } from '../change-stream';
import { CREATE } from './portal-user.schema';
import { withSchemaValidationTests } from '../test-helpers';
import { withTestsForBackendTestcase } from '../test-helpers/schemas/backend-tests/with-tests-for-backend-testcase';

describe('PORTAL_USER', () => {
describe('CREATE', () => {
withSchemaValidationTests({
withTestsForTestCases: withTestsForBackendTestcase,
schema: CREATE,
aValidPayload,
testCases: [
Expand Down
2 changes: 2 additions & 0 deletions libs/common/src/schemas/portal-user.schema.update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import z from 'zod';
import { generatePortalUserAuditDatabaseRecord } from '../change-stream';
import { UPDATE } from './portal-user.schema';
import { withSchemaValidationTests } from '../test-helpers';
import { withTestsForBackendTestcase } from '../test-helpers/schemas/backend-tests/with-tests-for-backend-testcase';

describe('PORTAL_USER', () => {
describe('UPDATE', () => {
withSchemaValidationTests({
withTestsForTestCases: withTestsForBackendTestcase,
schema: UPDATE,
schemaTestOptions: {
isPartial: true,
Expand Down
2 changes: 2 additions & 0 deletions libs/common/src/schemas/tfm/tfm-user.schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { withSchemaValidationTests } from '../../test-helpers';
import { TfmUser } from '../../types';
import { TFM_USER_SCHEMA } from './tfm-user.schema';
import { TEAM_IDS } from '../../constants';
import { withTestsForBackendTestcase } from '../../test-helpers/schemas/backend-tests/with-tests-for-backend-testcase';

describe('TFM_USER_SCHEMA', () => {
withSchemaValidationTests({
withTestsForTestCases: withTestsForBackendTestcase,
schema: TFM_USER_SCHEMA,
aValidPayload,
testCases: [
Expand Down
2 changes: 2 additions & 0 deletions libs/common/src/schemas/tfm/update-tfm-user.schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { withSchemaValidationTests } from '../../test-helpers';
import { UpdateTfmUserRequest } from '../../types';
import { TEAM_IDS } from '../../constants';
import { UPDATE_TFM_USER_REQUEST_SCHEMA } from './update-tfm-user-request.schema';
import { withTestsForBackendTestcase } from '../../test-helpers/schemas/backend-tests/with-tests-for-backend-testcase';

describe('UPDATE_TFM_USER_SCHEMA', () => {
withSchemaValidationTests({
withTestsForTestCases: withTestsForBackendTestcase,
schema: UPDATE_TFM_USER_REQUEST_SCHEMA,
schemaTestOptions: {
isPartial: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { generateTfmUserAuditDatabaseRecord } from '../../../change-stream';
import { withDefaultOptionsTests } from '../primitive-types-tests';
import { withSchemaValidationTests } from '../with-schema-validation.tests';
import { withTestsForBackendTestcase } from '../backend-tests/with-tests-for-backend-testcase';
import { BackendTestCase } from '../backend-test-cases/backend-test-cases';
import { BaseTestCase } from '../test-cases/base-test-case';

export const withAuditDatabaseRecordSchemaTests = <Schema extends ZodSchema>({
schema,
Expand All @@ -21,7 +21,7 @@ export const withAuditDatabaseRecordSchemaTests = <Schema extends ZodSchema>({
options,
});

withSchemaValidationTests<Schema, BackendTestCase>({
withSchemaValidationTests<Schema, BaseTestCase>({
withTestsForTestCases: withTestsForBackendTestcase,
schema,
aValidPayload: aValidAuditRecord,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { TestCase } from '../test-cases/test-case';
import { TestCaseWithType } from '../types/test-case-with-type.type';

export type BackendTestCase =
| TestCase
| TestCaseWithType<'OBJECT_ID_SCHEMA'>
| TestCaseWithType<'OBJECT_ID_STRING_SCHEMA'>
| TestCaseWithType<'OBJECT_ID_OR_OBJECT_ID_STRING_SCHEMA'>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { ZodSchema } from 'zod';
import { BackendTestCase } from '../backend-test-cases/backend-test-cases';
import { withObjectIdSchemaTests } from '../backend-custom-types-tests/with-object-id-schema.tests';
import { withObjectIdStringSchemaTests } from '../backend-custom-types-tests/with-object-id-string-schema.tests';
import { withObjectIdOrObjectIdStringSchemaTests } from '../backend-custom-types-tests/with-object-id-or-object-id-string-schema.tests';
import { withAuditDatabaseRecordSchemaTests } from '../backend-schema-tests';
import { WithTestsForTestCaseProps } from '../types/with-tests-for-test-case';
import { withTestsForTestcase } from '../tests/with-tests-for-testcase';
import { BaseTestCase } from '../test-cases/base-test-case';

/**
* Gets tests for a test case, using the test case type to determine which tests to run
*
* These tests are all available tests that can be easily used to test a parameter, and should be extended
*/
export const withTestsForBackendTestcase = <Schema extends ZodSchema>(props: WithTestsForTestCaseProps<Schema, BackendTestCase>): void => {
export const withTestsForBackendTestcase = <Schema extends ZodSchema>(props: WithTestsForTestCaseProps<Schema, BaseTestCase>): void => {
const { schema, testCase, getTestObjectWithUpdatedParameter, getUpdatedParameterFromParsedTestObject } = props;
const { type, options } = testCase;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { BackendTestCase } from '../backend-test-cases/backend-test-cases';
import { TestCase } from './test-case';

export type BaseTestCase = TestCase | BackendTestCase;
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import { withStringTests, withNumberTests, withBooleanTests, withArrayTests } fr
import { withEntraIdUserSchemaTests, withUpsertTfmUserRequestSchemaTests } from '../schema-tests';
import { withIsoDateTimeStampToDateSchemaTests } from '../transformation-tests';
import { WithTestsForTestCaseProps } from '../types/with-tests-for-test-case';
import { TestCase } from '../test-cases/test-case';
import { BaseTestCase } from '../test-cases/base-test-case';

/**
* Gets tests for a test case, using the test case type to determine which tests to run
*
* These tests are all available tests that can be easily used to test a parameter, and should be extended
*/
export const withTestsForTestcase = <Schema extends ZodSchema>(props: WithTestsForTestCaseProps<Schema, TestCase>): void => {
export const withTestsForTestcase = <Schema extends ZodSchema>(props: WithTestsForTestCaseProps<Schema, BaseTestCase>): void => {
const { schema, testCase, getTestObjectWithUpdatedParameter, getUpdatedParameterFromParsedTestObject } = props;
const { type, options } = testCase;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { TestCase } from '../test-cases/test-case';
import { BaseTestCase } from '../test-cases/base-test-case';

/**
* Test cases with the path parameter, used to create the getTestObjectWithUpdatedParameter function
*/
export type TestCaseWithPathParameter<T extends TestCase> = {
export type TestCaseWithPathParameter<T extends BaseTestCase> = {
parameterPath: string;
} & T;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type WithTestsForTestCaseProps<Schema, TestCase> = {
export type WithTestsForTestCaseProps<Schema, T> = {
schema: Schema;
testCase: TestCase;
testCase: T;
getTestObjectWithUpdatedParameter: (newValue: unknown) => unknown;
getUpdatedParameterFromParsedTestObject: (parsedTestObject: unknown) => unknown;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { withTestsForTestcase } from './tests/with-tests-for-testcase';
import { SchemaTestOptions } from './types/schema-test-options.type';
import { TestCaseWithPathParameter } from './types/test-case-with-path-parameter.type';
import { WithTestsForTestCaseProps } from './types/with-tests-for-test-case';
import { TestCase } from './test-cases/test-case';
import { BaseTestCase } from './test-cases/base-test-case';

/**
* This function orchestrates a schema's test cases.
Expand Down Expand Up @@ -67,7 +67,7 @@ import { TestCase } from './test-cases/test-case';
* }]
* ```
*/
export const withSchemaValidationTests = <Schema extends ZodSchema, T extends TestCase>({
export const withSchemaValidationTests = <Schema extends ZodSchema, T extends BaseTestCase>({
schema,
schemaTestOptions = {},
aValidPayload,
Expand Down

0 comments on commit 5f3b106

Please sign in to comment.