From 6c02e8b857321f5743c36a35629a09150a63d630 Mon Sep 17 00:00:00 2001 From: Dan Teixeira Date: Thu, 17 Nov 2022 06:38:45 -0300 Subject: [PATCH] Revert "feat(sync-action): add support for quote requests (#1815)" This reverts commit 97c21ea20c777d9d7712d498bda7171a0c7e4822. --- .../src/quote-requests-actions.js | 16 --- packages/sync-actions/src/quote-requests.js | 72 ---------- .../test/quote-requests-sync.spec.js | 127 ------------------ 3 files changed, 215 deletions(-) delete mode 100644 packages/sync-actions/src/quote-requests-actions.js delete mode 100644 packages/sync-actions/src/quote-requests.js delete mode 100644 packages/sync-actions/test/quote-requests-sync.spec.js diff --git a/packages/sync-actions/src/quote-requests-actions.js b/packages/sync-actions/src/quote-requests-actions.js deleted file mode 100644 index c723cf695..000000000 --- a/packages/sync-actions/src/quote-requests-actions.js +++ /dev/null @@ -1,16 +0,0 @@ -import { buildBaseAttributesActions } from './utils/common-actions' - -export const baseActionsList = [ - { action: 'changeQuoteRequestState', key: 'quoteRequestState' }, - { action: 'transitionState', key: 'state'}, -] - -export function actionsMapBase(diff, oldObj, newObj, config = {}) { - return buildBaseAttributesActions({ - actions: baseActionsList, - diff, - oldObj, - newObj, - shouldOmitEmptyString: config.shouldOmitEmptyString, - }) -} diff --git a/packages/sync-actions/src/quote-requests.js b/packages/sync-actions/src/quote-requests.js deleted file mode 100644 index 728724c3f..000000000 --- a/packages/sync-actions/src/quote-requests.js +++ /dev/null @@ -1,72 +0,0 @@ -/* @flow */ -import flatten from 'lodash.flatten' -import type { - SyncAction, - SyncActionConfig, - ActionGroup, - UpdateAction, -} from 'types/sdk' -import createBuildActions from './utils/create-build-actions' -import createMapActionGroup from './utils/create-map-action-group' -import actionsMapCustom from './utils/action-map-custom' -import * as QuoteRequestsActions from './quote-requests-actions' -import * as diffpatcher from './utils/diffpatcher' - -const actionGroups = [ - 'base', - 'custom', -] - -function createQuoteRequestsMapActions( - mapActionGroup: Function, - syncActionConfig: SyncActionConfig -): ( - diff: Object, - newObj: Object, - oldObj: Object, - options: Object -) => Array { - return function doMapActions( - diff: Object, - newObj: Object, - oldObj: Object, - ): Array { - const allActions = [] - - allActions.push( - mapActionGroup('base', (): Array => - QuoteRequestsActions.actionsMapBase( - diff, - oldObj, - newObj, - syncActionConfig - ) - ) - ) - - allActions.push( - mapActionGroup('custom', (): Array => - actionsMapCustom(diff, newObj, oldObj) - ) - ) - - return flatten(allActions) - } -} - -export default ( - actionGroupList: Array, - syncActionConfig: SyncActionConfig -): SyncAction => { - const mapActionGroup = createMapActionGroup(actionGroupList) - const doMapActions = createQuoteRequestsMapActions(mapActionGroup, syncActionConfig) - - const buildActions = createBuildActions( - diffpatcher.diff, - doMapActions, - ) - - return { buildActions } -} - -export { actionGroups } diff --git a/packages/sync-actions/test/quote-requests-sync.spec.js b/packages/sync-actions/test/quote-requests-sync.spec.js deleted file mode 100644 index 1ce072d7f..000000000 --- a/packages/sync-actions/test/quote-requests-sync.spec.js +++ /dev/null @@ -1,127 +0,0 @@ -import createQuoteRequestsSync, { actionGroups } from '../src/quote-requests' -import { baseActionsList } from '../src/quote-requests-actions' - -describe('Exports', () => { - test('action group list', () => { - expect(actionGroups).toEqual(['base', 'custom']) - }) - - describe('action list', () => { - test('should contain `changeQuoteRequestState` action', () => { - expect(baseActionsList).toEqual( - expect.arrayContaining([{ action: 'changeQuoteRequestState', key: 'quoteRequestState' }]) - ) - }) - - test('should contain `transitionState` action', () => { - expect(baseActionsList).toEqual( - expect.arrayContaining([{ action: 'transitionState', key: 'state' }]) - ) - }) - }) -}) - -describe('Actions', () => { - let quoteRequestsSync - beforeEach(() => { - quoteRequestsSync = createQuoteRequestsSync() - }) - - test('should build `changeQuoteRequestState` action', () => { - const before = { quoteRequestState: 'Submitted' } - const now = { quoteRequestState: 'Accepted' } - const actual = quoteRequestsSync.buildActions(now, before) - const expected = [ - { - action: 'changeQuoteRequestState', - ...now - } - ] - expect(actual).toEqual(expected) - }) - - test('should build `transitionState` action', () => { - const before = { - state : { - typeId : 'state', - id : 'sid1' - } - } - const now = { - state : { - typeId : 'state', - id : 'sid2' - } - } - const actual = quoteRequestsSync.buildActions(now, before) - const expected = [ - { - action: 'transitionState', - ...now - } - ] - expect(actual).toEqual(expected) - }) - - test('should build `setCustomType` action', () => { - const before = { - custom: { - type: { - typeId: 'type', - id: 'customType1', - }, - fields: { - customField1: true, - }, - }, - } - const now = { - custom: { - type: { - typeId: 'type', - id: 'customType2', - }, - fields: { - customField1: true, - }, - }, - } - const actual = quoteRequestsSync.buildActions(now, before) - const expected = [{ action: 'setCustomType', ...now.custom }] - expect(actual).toEqual(expected) - }) - - test('should build `setCustomField` action', () => { - const before = { - custom: { - type: { - typeId: 'type', - id: 'customType1', - }, - fields: { - customField1: false, - }, - }, - } - const now = { - custom: { - type: { - typeId: 'type', - id: 'customType1', - }, - fields: { - customField1: true, - }, - }, - } - const actual = quoteRequestsSync.buildActions(now, before) - const expected = [ - { - action: 'setCustomField', - name: 'customField1', - value: true, - }, - ] - expect(actual).toEqual(expected) - }) -})