mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-12 15:44:06 -08:00
test: Fix failing tests on MySQL for Public API (#3520)
* ⚡ Generalize transformer * ⚡ Use transformer * 🧪 Fix expectations
This commit is contained in:
parent
55bab19eb4
commit
3ee384fd87
|
@ -21,7 +21,7 @@ import { Role } from './Role';
|
||||||
import { SharedWorkflow } from './SharedWorkflow';
|
import { SharedWorkflow } from './SharedWorkflow';
|
||||||
import { SharedCredentials } from './SharedCredentials';
|
import { SharedCredentials } from './SharedCredentials';
|
||||||
import { NoXss } from '../utils/customValidators';
|
import { NoXss } from '../utils/customValidators';
|
||||||
import { answersFormatter, lowerCaser } from '../utils/transformers';
|
import { objectRetriever, lowerCaser } from '../utils/transformers';
|
||||||
|
|
||||||
export const MIN_PASSWORD_LENGTH = 8;
|
export const MIN_PASSWORD_LENGTH = 8;
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ export class User {
|
||||||
@Column({
|
@Column({
|
||||||
type: resolveDataType('json') as ColumnOptions['type'],
|
type: resolveDataType('json') as ColumnOptions['type'],
|
||||||
nullable: true,
|
nullable: true,
|
||||||
transformer: answersFormatter,
|
transformer: objectRetriever,
|
||||||
})
|
})
|
||||||
personalizationAnswers: IPersonalizationSurveyAnswers | null;
|
personalizationAnswers: IPersonalizationSurveyAnswers | null;
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import * as config from '../../../config';
|
||||||
import { DatabaseType, IWorkflowDb } from '../..';
|
import { DatabaseType, IWorkflowDb } from '../..';
|
||||||
import { TagEntity } from './TagEntity';
|
import { TagEntity } from './TagEntity';
|
||||||
import { SharedWorkflow } from './SharedWorkflow';
|
import { SharedWorkflow } from './SharedWorkflow';
|
||||||
|
import { objectRetriever } from '../utils/transformers';
|
||||||
|
|
||||||
function resolveDataType(dataType: string) {
|
function resolveDataType(dataType: string) {
|
||||||
const dbType = config.getEnv('database.type');
|
const dbType = config.getEnv('database.type');
|
||||||
|
@ -95,6 +96,7 @@ export class WorkflowEntity implements IWorkflowDb {
|
||||||
@Column({
|
@Column({
|
||||||
type: resolveDataType('json') as ColumnOptions['type'],
|
type: resolveDataType('json') as ColumnOptions['type'],
|
||||||
nullable: true,
|
nullable: true,
|
||||||
|
transformer: objectRetriever,
|
||||||
})
|
})
|
||||||
staticData?: IDataObject;
|
staticData?: IDataObject;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
// eslint-disable-next-line import/no-cycle
|
import { ValueTransformer } from 'typeorm';
|
||||||
import { IPersonalizationSurveyAnswers } from '../../Interfaces';
|
|
||||||
|
|
||||||
export const idStringifier = {
|
export const idStringifier = {
|
||||||
from: (value: number): string | number => (typeof value === 'number' ? value.toString() : value),
|
from: (value: number): string | number => (typeof value === 'number' ? value.toString() : value),
|
||||||
|
@ -12,14 +11,10 @@ export const lowerCaser = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure a consistent return type for personalization answers in `User`.
|
* Unmarshal JSON as JS object.
|
||||||
* Answers currently stored as `TEXT` on Postgres.
|
|
||||||
*/
|
*/
|
||||||
export const answersFormatter = {
|
export const objectRetriever: ValueTransformer = {
|
||||||
to: (answers: IPersonalizationSurveyAnswers): IPersonalizationSurveyAnswers => answers,
|
to: (value: object): object => value,
|
||||||
from: (answers: IPersonalizationSurveyAnswers | string): IPersonalizationSurveyAnswers => {
|
from: (value: string | object): object =>
|
||||||
return typeof answers === 'string'
|
typeof value === 'string' ? (JSON.parse(value) as object) : value,
|
||||||
? (JSON.parse(answers) as IPersonalizationSurveyAnswers)
|
|
||||||
: answers;
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1160,7 +1160,7 @@ test('PUT /workflows/:id should update workflow', async () => {
|
||||||
expect(name).toBe(payload.name);
|
expect(name).toBe(payload.name);
|
||||||
expect(connections).toEqual(payload.connections);
|
expect(connections).toEqual(payload.connections);
|
||||||
expect(settings).toEqual(payload.settings);
|
expect(settings).toEqual(payload.settings);
|
||||||
expect(staticData).toEqual(payload.staticData);
|
expect(staticData).toMatchObject(JSON.parse(payload.staticData));
|
||||||
expect(nodes).toEqual(payload.nodes);
|
expect(nodes).toEqual(payload.nodes);
|
||||||
expect(active).toBe(false);
|
expect(active).toBe(false);
|
||||||
expect(createdAt).toBe(workflow.createdAt.toISOString());
|
expect(createdAt).toBe(workflow.createdAt.toISOString());
|
||||||
|
@ -1235,7 +1235,7 @@ test('PUT /workflows/:id should update non-owned workflow if owner', async () =>
|
||||||
expect(name).toBe(payload.name);
|
expect(name).toBe(payload.name);
|
||||||
expect(connections).toEqual(payload.connections);
|
expect(connections).toEqual(payload.connections);
|
||||||
expect(settings).toEqual(payload.settings);
|
expect(settings).toEqual(payload.settings);
|
||||||
expect(staticData).toEqual(payload.staticData);
|
expect(staticData).toMatchObject(JSON.parse(payload.staticData));
|
||||||
expect(nodes).toEqual(payload.nodes);
|
expect(nodes).toEqual(payload.nodes);
|
||||||
expect(active).toBe(false);
|
expect(active).toBe(false);
|
||||||
expect(createdAt).toBe(workflow.createdAt.toISOString());
|
expect(createdAt).toBe(workflow.createdAt.toISOString());
|
||||||
|
|
Loading…
Reference in a new issue