mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -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 { 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;
|
||||
|
||||
|
@ -98,7 +98,7 @@ export class User {
|
|||
@Column({
|
||||
type: resolveDataType('json') as ColumnOptions['type'],
|
||||
nullable: true,
|
||||
transformer: answersFormatter,
|
||||
transformer: objectRetriever,
|
||||
})
|
||||
personalizationAnswers: IPersonalizationSurveyAnswers | null;
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
@ -95,6 +96,7 @@ export class WorkflowEntity implements IWorkflowDb {
|
|||
@Column({
|
||||
type: resolveDataType('json') as ColumnOptions['type'],
|
||||
nullable: true,
|
||||
transformer: objectRetriever,
|
||||
})
|
||||
staticData?: IDataObject;
|
||||
|
||||
|
|
|
@ -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),
|
||||
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -1160,7 +1160,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());
|
||||
|
@ -1235,7 +1235,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());
|
||||
|
|
Loading…
Reference in a new issue