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

Fix failing tests on MySQL for Public API #3520

Merged
merged 3 commits into from
Jun 23, 2022
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
4 changes: 2 additions & 2 deletions packages/cli/src/databases/entities/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Role } from './Role';
import { SharedWorkflow } from './SharedWorkflow';
import { SharedCredentials } from './SharedCredentials';
import { NoXss } from '../utils/customValidators';
import { answersFormatter, lowerCaser } from '../utils/transformers';
import { objectRetriever, lowerCaser } from '../utils/transformers';

export const MIN_PASSWORD_LENGTH = 8;

Expand Down Expand Up @@ -98,7 +98,7 @@ export class User {
@Column({
type: resolveDataType('json') as ColumnOptions['type'],
nullable: true,
transformer: answersFormatter,
transformer: objectRetriever,
})
personalizationAnswers: IPersonalizationSurveyAnswers | null;

Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/databases/entities/WorkflowEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as config from '../../../config';
import { DatabaseType, IWorkflowDb } from '../..';
import { TagEntity } from './TagEntity';
import { SharedWorkflow } from './SharedWorkflow';
import { objectRetriever } from '../utils/transformers';

function resolveDataType(dataType: string) {
const dbType = config.getEnv('database.type');
Expand Down Expand Up @@ -95,6 +96,7 @@ export class WorkflowEntity implements IWorkflowDb {
@Column({
type: resolveDataType('json') as ColumnOptions['type'],
nullable: true,
transformer: objectRetriever,
})
staticData?: IDataObject;

Expand Down
17 changes: 6 additions & 11 deletions packages/cli/src/databases/utils/transformers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// eslint-disable-next-line import/no-cycle
import { IPersonalizationSurveyAnswers } from '../../Interfaces';
import { ValueTransformer } from 'typeorm';

export const idStringifier = {
from: (value: number): string | number => (typeof value === 'number' ? value.toString() : value),
Expand All @@ -12,14 +11,10 @@ export const lowerCaser = {
};

/**
* Ensure a consistent return type for personalization answers in `User`.
* Answers currently stored as `TEXT` on Postgres.
* Unmarshal JSON as JS object.
*/
export const answersFormatter = {
to: (answers: IPersonalizationSurveyAnswers): IPersonalizationSurveyAnswers => answers,
from: (answers: IPersonalizationSurveyAnswers | string): IPersonalizationSurveyAnswers => {
return typeof answers === 'string'
? (JSON.parse(answers) as IPersonalizationSurveyAnswers)
: answers;
},
export const objectRetriever: ValueTransformer = {
to: (value: object): object => value,
from: (value: string | object): object =>
typeof value === 'string' ? (JSON.parse(value) as object) : value,
};
4 changes: 2 additions & 2 deletions packages/cli/test/integration/publicApi/workflows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ test('PUT /workflows/:id should update workflow', async () => {
expect(name).toBe(payload.name);
expect(connections).toEqual(payload.connections);
expect(settings).toEqual(payload.settings);
expect(staticData).toEqual(payload.staticData);
expect(staticData).toMatchObject(JSON.parse(payload.staticData));
expect(nodes).toEqual(payload.nodes);
expect(active).toBe(false);
expect(createdAt).toBe(workflow.createdAt.toISOString());
Expand Down Expand Up @@ -1231,7 +1231,7 @@ test('PUT /workflows/:id should update non-owned workflow if owner', async () =>
expect(name).toBe(payload.name);
expect(connections).toEqual(payload.connections);
expect(settings).toEqual(payload.settings);
expect(staticData).toEqual(payload.staticData);
expect(staticData).toMatchObject(JSON.parse(payload.staticData));
expect(nodes).toEqual(payload.nodes);
expect(active).toBe(false);
expect(createdAt).toBe(workflow.createdAt.toISOString());
Expand Down