File size: 1,161 Bytes
3206347
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { describe, it, expect, beforeEach } from 'vitest';
import { createFlow } from '../../test/factories/flow';
import flowSerializer from './flow';
import stepSerializer from './step';
import { createStep } from '../../test/factories/step';

describe('flowSerializer', () => {
  let flow, stepOne, stepTwo;

  beforeEach(async () => {
    flow = await createFlow();

    stepOne = await createStep({
      flowId: flow.id,
      type: 'trigger',
    });

    stepTwo = await createStep({
      flowId: flow.id,
      type: 'action',
    });
  });

  it('should return flow data', async () => {
    const expectedPayload = {
      id: flow.id,
      name: flow.name,
      active: flow.active,
      status: flow.status,
      createdAt: flow.createdAt.getTime(),
      updatedAt: flow.updatedAt.getTime(),
    };

    expect(flowSerializer(flow)).toEqual(expectedPayload);
  });

  it('should return flow data with the steps', async () => {
    flow.steps = [stepOne, stepTwo];

    const expectedPayload = {
      steps: [stepSerializer(stepOne), stepSerializer(stepTwo)],
    };

    expect(flowSerializer(flow)).toMatchObject(expectedPayload);
  });
});