aboutsummaryrefslogtreecommitdiffstats
path: root/packages/pipeline/test/parsers/copper/index_test.ts
blob: bb8e70da16e925ce993c2927481ba62bcb61e29f (plain) (blame)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import * as chai from 'chai';
import 'mocha';

import {
    CopperActivity,
    CopperActivityType,
    CopperCustomField,
    CopperLead,
    CopperOpportunity,
} from '../../../src/entities';
import {
    CopperActivityResponse,
    CopperActivityTypeCategory,
    CopperActivityTypeResponse,
    CopperCustomFieldResponse,
    CopperSearchResponse,
    parseActivities,
    parseActivityTypes,
    parseCustomFields,
    parseLeads,
    parseOpportunities,
} from '../../../src/parsers/copper';
import { chaiSetup } from '../../utils/chai_setup';

chaiSetup.configure();
const expect = chai.expect;

type CopperResponse = CopperSearchResponse | CopperCustomFieldResponse;
type CopperEntity = CopperLead | CopperActivity | CopperOpportunity | CopperActivityType | CopperCustomField;

import * as activityTypesApiResponse from '../../fixtures/copper/api_v1_activity_types.json';
import * as customFieldsApiResponse from '../../fixtures/copper/api_v1_custom_field_definitions.json';
import * as listActivitiesApiResponse from '../../fixtures/copper/api_v1_list_activities.json';
import * as listLeadsApiResponse from '../../fixtures/copper/api_v1_list_leads.json';
import * as listOpportunitiesApiResponse from '../../fixtures/copper/api_v1_list_opportunities.json';
import {
    ParsedActivities,
    ParsedActivityTypes,
    ParsedCustomFields,
    ParsedLeads,
    ParsedOpportunities,
} from '../../fixtures/copper/parsed_entities';

interface TestCase {
    input: CopperResponse[];
    expected: CopperEntity[];
    parseFn(input: CopperResponse[]): CopperEntity[];
}
const testCases: TestCase[] = [
    {
        input: listLeadsApiResponse,
        expected: ParsedLeads,
        parseFn: parseLeads,
    },
    {
        input: (listActivitiesApiResponse as unknown) as CopperActivityResponse[],
        expected: ParsedActivities,
        parseFn: parseActivities,
    },
    {
        input: listOpportunitiesApiResponse,
        expected: ParsedOpportunities,
        parseFn: parseOpportunities,
    },
    {
        input: customFieldsApiResponse,
        expected: ParsedCustomFields,
        parseFn: parseCustomFields,
    },
];
describe('Copper parser', () => {
    it('parses API responses', () => {
        testCases.forEach(testCase => {
            const actual: CopperEntity[] = testCase.parseFn(testCase.input);
            expect(actual).deep.equal(testCase.expected);
        });
    });

    // special case because the API response is not an array
    it('parses activity types API response', () => {
        const actual: CopperActivityType[] = parseActivityTypes((activityTypesApiResponse as unknown) as Map<
            CopperActivityTypeCategory,
            CopperActivityTypeResponse[]
        >);
        expect(actual).deep.equal(ParsedActivityTypes);
    });
});