From b42fff9aba5aca645e8f8439d0b5f840d113a181 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Wed, 9 Feb 2022 18:36:49 -0300 Subject: [PATCH 01/14] Add entities to entities.ts --- src/entities.ts | 98 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/src/entities.ts b/src/entities.ts index d363f0b..2f46bc4 100644 --- a/src/entities.ts +++ b/src/entities.ts @@ -46,7 +46,103 @@ const entities: EntityMap = { { on: 'req', del: 'event.description.text' }, ] } - }, + }, + }, + category: { + actions: { + load: { + request: { + method: "get", + path: "/categories/:category_id/", + }, + }, + } + }, + discount: { + actions: { + load: { + request: { + method: "get", + path: "/discounts/:discount_id/", + }, + after: [ + { on: 'outent', field: 'discount_id', set: { query: 'discount_id' } } + ] + }, + save: { + request: { + method: "post", + path: "/discounts/:discount_id", + body: { + discount: [ + 'type', + 'code', + 'amount_off', + 'percent_off', + 'event_id', + 'ticket_class_ids', + 'quantity_available', + 'start_date', + 'start_date_relative', + 'end_date', + 'end_date_relative', + 'ticket_group_id', + 'hold_ids', + ] + }, + }, + after: [ + { on: 'outent', field: 'discount_id', set: { inent: 'discount_id' } } + ] + } + }, + }, + inventory_tier: { + actions: { + load: { + request: { + method: 'get', + path: "/events/:event_id/inventory_tiers/:inventory_tier/", + } + }, + save: { + request: { + method: 'post', + path: "/events/:event_id/inventory_tiers/:inventory_tier/", + body: { + inventory_tier: [ + 'name', + 'sort_order', + 'color', + 'quantity_total', + 'image_id', + 'capacity_total', + 'holds', + ] + } + }, + } + } + }, + event_team: { + actions: { + load: { + request: { + method: "get", + path: "/events/:event_id/teams/:team_id", + }, + }, + } + }, + attendee: { + actions: { + load: { + request: { + method: "get", + path: "/events/:event_id/attendees/:attendee_id/", + } + } + } } } From 08a858e650fce73e37b58fb0ffe6e83f3104badb Mon Sep 17 00:00:00 2001 From: Gustavo Date: Wed, 9 Feb 2022 18:37:25 -0300 Subject: [PATCH 02/14] Add entities data for testing and mock data --- test/ents-tests.ts | 108 ++++++++++++++++++++++++++++++++++++++++++++- test/mocks.ts | 63 ++++++++++++++++++++++++++ 2 files changed, 169 insertions(+), 2 deletions(-) diff --git a/test/ents-tests.ts b/test/ents-tests.ts index 6c4e0ed..dcd103b 100644 --- a/test/ents-tests.ts +++ b/test/ents-tests.ts @@ -1,7 +1,13 @@ import { TestEntityMap } from "./types" -let test_args = { - event_id: '238083523227' +const test_args = { + event_id: '238083523227', //238083523227 251037679457 + inventory_tier: '11195969', + discount_id: '609282579', + category_id: '101', + team_id: '1234', + attendee_id: '1234', + organization_id: '39198188963 ', } const ents_tests: TestEntityMap = { @@ -35,6 +41,104 @@ const ents_tests: TestEntityMap = { }, }, }, + category: { + load: { + args: { + category_id: test_args.category_id, + }, + expectations: { + id: { + sameAs: test_args.category_id, + }, + }, + }, + }, + discount: { + load: { + args: { + discount_id: test_args.discount_id, + }, + expectations: { + id: { + sameAs: test_args.discount_id, + }, + }, + }, + save: { + changes: { + code: 'democode', + }, + expectations: { + id: { + sameAs: test_args.discount_id, + }, + code: { + sameAs: 'democode' + } + }, + }, + }, + inventory_tier: { + load: { + args: { + event_id: test_args.event_id, + inventory_tier: test_args.inventory_tier + }, + expectations: { + id: { + sameAs: test_args.inventory_tier, + }, + event_id: { + sameAs: test_args.event_id, + }, + }, + }, + save: { + changes: { + name: 'random', + }, + expectations: { + id: { + sameAs: test_args.inventory_tier, + }, + event_id: { + sameAs: test_args.event_id, + }, + }, + }, + }, + event_team: { + load: { + args: { + event_id: test_args.event_id, + team_id: test_args.team_id, + }, + expectations: { + id: { + sameAs: test_args.team_id, + }, + event_id: { + sameAs: test_args.event_id, + }, + }, + }, + }, + attendee: { + load: { + args: { + event_id: test_args.event_id, + attendee_id: test_args.attendee_id, + }, + expectations: { + id: { + sameAs: test_args.attendee_id, + }, + event_id: { + sameAs: test_args.event_id, + }, + }, + }, + } } export { ents_tests } diff --git a/test/mocks.ts b/test/mocks.ts index f1c25cf..da4c64d 100644 --- a/test/mocks.ts +++ b/test/mocks.ts @@ -15,6 +15,69 @@ const mocks = { }, }, }, + category: { + get: { + url: "/categories/:category_id/", + mock_data: { + id: "101", + }, + }, + }, + discount: { + get: { + url: "/discounts/:discount_id", + mock_data: { + id: '609282579', + } + }, + post: { + url: "/discounts/:discount_id", + mock_data: { + id: '609282579', + code: 'democode' + } + } + }, + inventory_tier: { + get: { + url: "/events/:event_id/inventory_tiers/:inventory_tier/", + mock_data: { + inventory_tier: { + id: '11195969', + event_id: '238083523227', + name: '26ebbd125e7ccc13ee6f', + } + } + }, + post: { + url: "/events/:event_id/inventory_tiers/:inventory_tier/", + mock_data: { + inventory_tier: { + id: '11195969', + event_id: '238083523227', + name: '26ebbd125e7ccc13ee6f', + } + } + }, + }, + event_team: { + get: { + url: "/events/:event_id/teams/:team_id", + mock_data: { + id: "1234", + event_id: "238083523227", + }, + }, + }, + attendee: { + get: { + url: "/events/:event_id/attendees/:attendee_id/", + mock_data: { + id: "1234", + event_id: "238083523227" + }, + }, + } } export { mocks } From 2b6330a6f5b8c7d93f0d61260e6fcc2a6861e01a Mon Sep 17 00:00:00 2001 From: Gustavo Date: Wed, 9 Feb 2022 18:38:14 -0300 Subject: [PATCH 03/14] Refactor make-actions.ts --- src/make-actions.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/make-actions.ts b/src/make-actions.ts index fdd6ab5..c0ebca3 100644 --- a/src/make-actions.ts +++ b/src/make-actions.ts @@ -38,21 +38,21 @@ function make_actions(action_data: ActionData) { const { q, ent } = msg let body: Record = {} - let context: Context = { - query: q, - inent: ent, - } - const built_path = build_path(path, ent) if(action_data.details.request.body) { body = fill_body(action_data.details.request.body, ent) } - if(before) { - context = perform_tasks(before, {...context, req: body}) + let context: Context = { + query: q, + inent: ent, + req: body } + if(before) { + context = perform_tasks(before, context) + } const res = await req_fn(built_path, { body: JSON.stringify(context.req) From cfe1042659a495d41443eb1a5a6699e7ca1ec34f Mon Sep 17 00:00:00 2001 From: Gustavo Date: Thu, 10 Feb 2022 10:30:44 -0300 Subject: [PATCH 04/14] Add entities and mock data --- src/entities.ts | 48 +++++++++++++++++++++++++++++++++++++++++++++- test/ents-tests.ts | 38 ++++++++++++++++++++++++++++++++++++ test/mocks.ts | 42 ++++++++++++++++++++++++++++++---------- 3 files changed, 117 insertions(+), 11 deletions(-) diff --git a/src/entities.ts b/src/entities.ts index 2f46bc4..0dfa823 100644 --- a/src/entities.ts +++ b/src/entities.ts @@ -143,7 +143,53 @@ const entities: EntityMap = { } } } - } + }, + format: { + actions: { + load: { + request: { + method: 'get', + path: '/formats/:format_id/' + }, + } + } + }, + display_settings: { + actions: { + load: { + request: { + method: 'get', + path: '/events/:event_id/display_settings/' + }, + after: [ + { on: 'outent', field: 'event_id', set: { query: 'event_id' } } + ] + }, + save: { + request: { + method: 'post', + path: '/events/:event_id/display_settings/', + body: { + display_settings: [ + 'show_start_date', + 'show_end_date', + 'show_start_end_time', + 'show_timezone', + 'show_map', + 'show_remaining', + 'show_organizer_facebook', + 'show_organizer_twitter', + 'show_facebook_friends_going', + 'terminology', + ] + } + }, + after: [ + { on: 'outent', field: 'event_id', set: { inent: 'event_id' } } + ] + } + } + }, } export { entities } \ No newline at end of file diff --git a/test/ents-tests.ts b/test/ents-tests.ts index dcd103b..dbe5a7e 100644 --- a/test/ents-tests.ts +++ b/test/ents-tests.ts @@ -8,6 +8,7 @@ const test_args = { team_id: '1234', attendee_id: '1234', organization_id: '39198188963 ', + format_id: '100', } const ents_tests: TestEntityMap = { @@ -138,6 +139,43 @@ const ents_tests: TestEntityMap = { }, }, }, + }, + format: { + load: { + args: { + format_id: test_args.format_id, + }, + expectations: { + id: { + sameAs: test_args.format_id, + }, + }, + }, + }, + display_settings: { + load: { + args: { + event_id: test_args.event_id, + }, + expectations: { + event_id: { + sameAs: test_args.event_id, + }, + }, + }, + save: { + changes: { + show_start_date: true, + }, + expectations: { + event_id: { + sameAs: test_args.event_id, + }, + show_start_date: { + sameAs: true + } + }, + }, } } diff --git a/test/mocks.ts b/test/mocks.ts index da4c64d..876b874 100644 --- a/test/mocks.ts +++ b/test/mocks.ts @@ -42,21 +42,17 @@ const mocks = { get: { url: "/events/:event_id/inventory_tiers/:inventory_tier/", mock_data: { - inventory_tier: { - id: '11195969', - event_id: '238083523227', - name: '26ebbd125e7ccc13ee6f', - } + id: '11195969', + event_id: '238083523227', + name: '26ebbd125e7ccc13ee6f', } }, post: { url: "/events/:event_id/inventory_tiers/:inventory_tier/", mock_data: { - inventory_tier: { - id: '11195969', - event_id: '238083523227', - name: '26ebbd125e7ccc13ee6f', - } + id: '11195969', + event_id: '238083523227', + name: '26ebbd125e7ccc13ee6f', } }, }, @@ -77,6 +73,32 @@ const mocks = { event_id: "238083523227" }, }, + }, + format: { + get: { + url: '/formats/:format_id/', + mock_data: { + id: "100", + }, + }, + }, + display_settings: { + get: { + url: '/events/:event_id/display_settings/', + mock_data: { + event_id: "238083523227", + show_start_date: true, + resource_uri: 'https://www.eventbriteapi.com/v3/events/238083523227/display_settings/', + }, + }, + post: { + url: '/events/:event_id/display_settings/', + mock_data: { + event_id: "238083523227", + show_start_date: true, + resource_uri: 'https://www.eventbriteapi.com/v3/events/238083523227/display_settings/', + }, + } } } From 93035f9c631ac92d442bb196fc766cae676df736 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Mon, 14 Feb 2022 10:48:06 -0300 Subject: [PATCH 05/14] refactor: formatting --- src/entities.ts | 116 ++++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/src/entities.ts b/src/entities.ts index 0dfa823..33c901c 100644 --- a/src/entities.ts +++ b/src/entities.ts @@ -1,42 +1,42 @@ -import { EntityMap } from "./types"; +import { EntityMap } from './types'; const entities: EntityMap = { event: { actions: { load: { request: { - method: "get", - path: "/events/:event_id/", + method: 'get', + path: '/events/:event_id/', }, after: [ - { on: 'outent', field: 'event_id', set: { query: 'event_id' } } - ] + { on: 'outent', field: 'event_id', set: { query: 'event_id' } }, + ], }, save: { request: { - method: "post", - path: "/events/:event_id/", + method: 'post', + path: '/events/:event_id/', body: { event: [ 'name', - 'description', - 'start', - 'end', + 'description', + 'start', + 'end', 'currency', 'online_event', 'organizer_id', 'listed', - 'shareable', - 'invite_only', + 'shareable', + 'invite_only', 'show_remaining', 'password', 'capacity', 'is_reserved_seating', - 'is_series', + 'is_series', 'show_pick_a_seat', 'show_seatmap_thumbnail', 'show_colors_in_seatmap_thumbnail', - ] + ], }, }, before: [ @@ -44,35 +44,35 @@ const entities: EntityMap = { { on: 'req', del: 'event.end.local' }, { on: 'req', del: 'event.name.text' }, { on: 'req', del: 'event.description.text' }, - ] - } + ], + }, }, }, category: { actions: { load: { request: { - method: "get", - path: "/categories/:category_id/", + method: 'get', + path: '/categories/:category_id/', }, }, - } + }, }, discount: { actions: { load: { request: { - method: "get", - path: "/discounts/:discount_id/", + method: 'get', + path: '/discounts/:discount_id/', }, after: [ - { on: 'outent', field: 'discount_id', set: { query: 'discount_id' } } - ] + { on: 'outent', field: 'discount_id', set: { query: 'discount_id' } }, + ], }, save: { request: { - method: "post", - path: "/discounts/:discount_id", + method: 'post', + path: '/discounts/:discount_id', body: { discount: [ 'type', @@ -88,13 +88,13 @@ const entities: EntityMap = { 'end_date_relative', 'ticket_group_id', 'hold_ids', - ] + ], }, }, after: [ - { on: 'outent', field: 'discount_id', set: { inent: 'discount_id' } } - ] - } + { on: 'outent', field: 'discount_id', set: { inent: 'discount_id' } }, + ], + }, }, }, inventory_tier: { @@ -102,13 +102,13 @@ const entities: EntityMap = { load: { request: { method: 'get', - path: "/events/:event_id/inventory_tiers/:inventory_tier/", - } + path: '/events/:event_id/inventory_tiers/:inventory_tier/', + }, }, save: { request: { method: 'post', - path: "/events/:event_id/inventory_tiers/:inventory_tier/", + path: '/events/:event_id/inventory_tiers/:inventory_tier/', body: { inventory_tier: [ 'name', @@ -118,52 +118,52 @@ const entities: EntityMap = { 'image_id', 'capacity_total', 'holds', - ] - } + ], + }, }, - } - } + }, + }, }, event_team: { actions: { load: { request: { - method: "get", - path: "/events/:event_id/teams/:team_id", + method: 'get', + path: '/events/:event_id/teams/:team_id', }, }, - } + }, }, attendee: { actions: { load: { request: { - method: "get", - path: "/events/:event_id/attendees/:attendee_id/", - } - } - } + method: 'get', + path: '/events/:event_id/attendees/:attendee_id/', + }, + }, + }, }, format: { actions: { load: { request: { method: 'get', - path: '/formats/:format_id/' + path: '/formats/:format_id/', }, - } - } + }, + }, }, display_settings: { actions: { load: { request: { method: 'get', - path: '/events/:event_id/display_settings/' + path: '/events/:event_id/display_settings/', }, after: [ - { on: 'outent', field: 'event_id', set: { query: 'event_id' } } - ] + { on: 'outent', field: 'event_id', set: { query: 'event_id' } }, + ], }, save: { request: { @@ -181,15 +181,15 @@ const entities: EntityMap = { 'show_organizer_twitter', 'show_facebook_friends_going', 'terminology', - ] - } + ], + }, }, after: [ - { on: 'outent', field: 'event_id', set: { inent: 'event_id' } } - ] - } - } - }, + { on: 'outent', field: 'event_id', set: { inent: 'event_id' } }, + ], + }, + }, + }, } -export { entities } \ No newline at end of file +export { entities } From fdf6539d850ef295b8c782e17252c3cdbb5682e2 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Mon, 14 Feb 2022 11:31:13 -0300 Subject: [PATCH 06/14] Add entities and their tests instructions --- src/entities.ts | 140 +++++++++++++++++++++++++++++++++++ test/ents-tests.ts | 177 +++++++++++++++++++++++++++++++++++++++++++++ test/mocks.ts | 97 ++++++++++++++++++++++++- 3 files changed, 413 insertions(+), 1 deletion(-) diff --git a/src/entities.ts b/src/entities.ts index 33c901c..8f5b2f9 100644 --- a/src/entities.ts +++ b/src/entities.ts @@ -190,6 +190,146 @@ const entities: EntityMap = { }, }, }, + event_capacity: { + actions: { + load: { + request: { + method: 'get', + path: '/events/:event_id/capacity_tier/', + }, + }, + save: { + request: { + method: 'post', + path: '/events/:event_id/capacity_tier/', + body: { + capacity_tier: ['capacity_total', 'holds'], + }, + }, + }, + }, + }, + event_series: { + actions: { + load: { + request: { + method: 'get', + path: '/series/:event_series_id/', + }, + }, + }, + }, + order: { + actions: { + load: { + request: { + method: 'get', + path: '/orders/:order_id/', + }, + }, + }, + }, + sales_report: { + actions: { + load: { + request: { + method: 'get', + path: '/reports/sales?event_ids=:event_ids&event_status=:event_status&start_date=:start_date&end_date=:end_date&filter_by=:filter_by&group_by=:group_by&period=:period&date_facet=:date_facet&timezone=:timezoney', + }, + }, + }, + }, + attendee_report: { + actions: { + load: { + request: { + method: 'get', + path: '/reports/attendees?event_ids=:event_ids&event_status=:event_status&start_date=:start_date&end_date=:end_date&filter_by=:filter_by&group_by=:group_by&period=:period&date_facet=:date_facet&timezone=:timezoney', + }, + }, + }, + }, + published_structured_content: { + actions: { + load: { + request: { + method: 'get', + path: '/events/:id/structured_content?propose=:propose', + }, + }, + }, + }, + working_structured_content: { + actions: { + load: { + request: { + method: 'get', + path: '/events/:id/structured_content/edit?propose=:propose', + }, + }, + }, + }, + text_overrides: { + actions: { + load: { + request: { + method: 'get', + path: '/organizations/:organization_id/text_overrides/?locale=:locale&venue_id=:venue_id&event_id=:event_id&text_codes=:text_codes', + }, + }, + }, + }, + ticket_buyer_settings: { + actions: { + load: { + request: { + method: 'get', + path: '/events/:event_id/ticket_buyer_settings/', + }, + }, + }, + }, + ticket_class: { + actions: { + load: { + request: { + method: 'get', + path: '/events/:event_id/ticket_classes/:ticket_class_id/', + }, + after: [ + { on: 'outent', field: 'event_id', set: { query: 'event_id' } }, + { on: 'outent', field: 'ticket_class_id', set: { query: 'ticket_class_id' } } + ] + }, + save: { + request: { + method: 'post', + path: '/events/:event_id/ticket_classes/:ticket_class_id/', + body: { + ticket_class: [ + 'cost', + 'resource_uri', + 'image_id', + 'display_name', + 'quantity_sold', + 'sales_start', + 'sales_end', + 'hide_sale_dates', + 'auto_hide_before', + 'auto_hide_after', + 'secondary_assignment_enabled', + 'sales_end_relative', + 'ticket_classe' + ] + } + }, + after: [ + { on: 'outent', field: 'event_id', set: { inent: 'event_id' } }, + { on: 'outent', field: 'ticket_class_id', set: { inent: 'ticket_class_id' } } + ] + } + }, + } } export { entities } diff --git a/test/ents-tests.ts b/test/ents-tests.ts index dbe5a7e..35dc81e 100644 --- a/test/ents-tests.ts +++ b/test/ents-tests.ts @@ -9,6 +9,32 @@ const test_args = { attendee_id: '1234', organization_id: '39198188963 ', format_id: '100', + event_series_id: '100', + order_id: '1234', + ticket_class: { + ticket_class_id: '1234', + event_id: '238083523227', + name: 'foo', + cost: 'USD,1234' + }, + sales_report: { + event_ids: '1234', + event_status: 'foo', + start_date: 'foo', + end_date: 'foo', + filter_by: 'foo', + group_by: 'foo', + period: 'foo', + date_facet: 'foo', + timezone: 'foo', + }, + text_overrides: { + organization_id: '1234', + locale: '1234', + venue_id: '1234', + event_id: '1234', + text_codes: '1234', + } } const ents_tests: TestEntityMap = { @@ -176,6 +202,157 @@ const ents_tests: TestEntityMap = { } }, }, + }, + event_capacity: { + load: { + args: { + event_id: test_args.event_id, + }, + expectations: { + event_id: { + sameAs: test_args.event_id, + }, + }, + }, + save: { + changes: { + capacity_total: 10, + }, + expectations: { + capacity_total: { + sameAs: 10 + } + }, + }, + }, + event_series: { + load: { + args: { + event_series_id: test_args.event_series_id, + }, + expectations: { + id: { + sameAs: test_args.event_id, + }, + }, + }, + }, + order: { + load: { + args: { + order_id: test_args.order_id, + }, + expectations: { + id: { + sameAs: test_args.order_id + }, + }, + }, + }, + sales_report: { + load: { + args: { + event_ids: test_args.sales_report.event_ids, + event_status: test_args.sales_report.event_status, + start_date: test_args.sales_report.start_date, + end_date: test_args.sales_report.end_date, + filter_by: test_args.sales_report.filter_by, + group_by: test_args.sales_report.group_by, + period: test_args.sales_report.period, + date_facet: test_args.sales_report.date_facet, + timezone: test_args.sales_report.timezone, + }, + }, + }, + attendee_report: { + load: { + args: { + event_ids: test_args.sales_report.event_ids, + event_status: test_args.sales_report.event_status, + start_date: test_args.sales_report.start_date, + end_date: test_args.sales_report.end_date, + filter_by: test_args.sales_report.filter_by, + group_by: test_args.sales_report.group_by, + period: test_args.sales_report.period, + date_facet: test_args.sales_report.date_facet, + timezone: test_args.sales_report.timezone, + }, + }, + }, + published_structured_content: { + load: { + args: { + id: 1 + }, + expectations: { + access_type: { + sameAs: 'public' + }, + }, + }, + }, + working_structured_content: { + load: { + args: { + id: 1 + }, + expectations: { + access_type: { + sameAs: 'public' + }, + }, + }, + }, + text_overrides: { + load: { + args: { + organization_id: test_args.text_overrides.organization_id, + locale: test_args.text_overrides.locale, + venue_id: test_args.text_overrides.venue_id, + event_id: test_args.text_overrides.event_id, + text_codes: test_args.text_overrides.text_codes, + }, + expectations: { + text_code: { + sameAs: 'tickets_not_yet_on_sale' + }, + }, + }, + }, + ticket_buyer_settings: { + load: { + args: { + event_id: test_args.event_id + }, + expectations: { + event_id: { + sameAs: test_args.event_id + }, + }, + }, + }, + ticket_class: { + load: { + args: { + event_id: test_args.ticket_class.event_id, + ticket_class_id: test_args.ticket_class.ticket_class_id + }, + expectations: { + name: { + sameAs: test_args.ticket_class.name + }, + }, + }, + save: { + changes: { + cost: test_args.ticket_class.cost, + }, + expectations: { + cost: { + sameAs: test_args.ticket_class.cost + } + }, + } } } diff --git a/test/mocks.ts b/test/mocks.ts index 876b874..ca0cb06 100644 --- a/test/mocks.ts +++ b/test/mocks.ts @@ -99,7 +99,102 @@ const mocks = { resource_uri: 'https://www.eventbriteapi.com/v3/events/238083523227/display_settings/', }, } - } + }, + event_capacity: { + get: { + url: "/events/:event_id/capacity_tier/", + mock_data: { + event_id: '238083523227', + } + }, + post: { + url: "/events/:event_id/capacity_tier/", + mock_data: { + event_id: '238083523227', + capacity_total: 10 + } + }, + }, + event_series: { + get: { + url: "/series/:event_series_id/", + mock_data: { + id: '238083523227', + } + } + }, + order: { + get: { + url: "/orders/:order_id/", + mock_data: { + id: '1234', + } + } + }, + sales_report: { + get: { + url: "/reports/sales?event_ids=:event_ids&event_status=:event_status&start_date=:start_date&end_date=:end_date&filter_by=:filter_by&group_by=:group_by&period=:period&date_facet=:date_facet&timezone=:timezoney", + mock_data: { + id: '1234', + } + } + }, + attendee_report: { + get: { + url: "/reports/attendees?event_ids=:event_ids&event_status=:event_status&start_date=:start_date&end_date=:end_date&filter_by=:filter_by&group_by=:group_by&period=:period&date_facet=:date_facet&timezone=:timezoney", + mock_data: { + id: '1234', + } + } + }, + published_structured_content: { + get: { + url: "/events/:id/structured_content?propose=:propose", + mock_data: { + access_type: 'public', + } + } + }, + working_structured_content: { + get: { + url: "/events/:id/structured_content/edit?propose=:propose", + mock_data: { + access_type: 'public', + } + } + }, + text_overrides: { + get: { + url: "/organizations/:organization_id/text_overrides/?locale=:locale&venue_id=:venue_id&event_id=:event_id&text_codes=:text_codes", + mock_data: { + text_code: 'tickets_not_yet_on_sale', + } + } + }, + ticket_buyer_settings: { + get: { + url: "/events/:event_id/ticket_buyer_settings/", + mock_data: { + event_id: '238083523227', + } + }, + }, + ticket_class: { + get: { + url: "/events/:event_id/ticket_classes/:ticket_class_id/", + mock_data: { + name: 'foo', + cost: 'USD,2342' + } + }, + post: { + url: "/events/:event_id/ticket_classes/:ticket_class_id/", + mock_data: { + cost: 'USD,1234', + name: 'foo' + } + }, + }, } export { mocks } From 61e52a3bc658f0f152bc17ddfc9c0768d5bfd648 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Mon, 14 Feb 2022 11:32:42 -0300 Subject: [PATCH 07/14] Remove console statement from test files --- test/eventbrite-provider.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/eventbrite-provider.test.ts b/test/eventbrite-provider.test.ts index d5f9725..dd86027 100644 --- a/test/eventbrite-provider.test.ts +++ b/test/eventbrite-provider.test.ts @@ -114,7 +114,6 @@ describe('eventbrite-provider', () => { const load_test_data = test_data.load let res_data = await seneca.entity("provider/eventbrite/" + ent_name).load$(load_test_data.args) - console.log(ent_name,res_data) expect(res_data.entity$).toBe("provider/eventbrite/" + ent_name) From 1cdce53813da6e8706474b4e9957c456f2d8dd0a Mon Sep 17 00:00:00 2001 From: Gustavo Date: Mon, 14 Feb 2022 15:45:57 -0300 Subject: [PATCH 08/14] Add entities and their tests instructions --- src/entities.ts | 72 ++++++++++++++++++++++++++++++++++++++++++++-- test/ents-tests.ts | 61 ++++++++++++++++++++++++++++++++++++++- test/mocks.ts | 42 +++++++++++++++++++++++++++ 3 files changed, 172 insertions(+), 3 deletions(-) diff --git a/src/entities.ts b/src/entities.ts index 8f5b2f9..38a6cdd 100644 --- a/src/entities.ts +++ b/src/entities.ts @@ -274,7 +274,7 @@ const entities: EntityMap = { load: { request: { method: 'get', - path: '/organizations/:organization_id/text_overrides/?locale=:locale&venue_id=:venue_id&event_id=:event_id&text_codes=:text_codes', + path: '/organizations/:organization_id/text_overrides?locale=:locale&venue_id=:venue_id&event_id=:event_id&text_codes=:text_codes', }, }, }, @@ -329,7 +329,75 @@ const entities: EntityMap = { ] } }, - } + }, + ticket_group: { + actions: { + load: { + request: { + method: 'get', + path: '/ticket_groups/:ticket_group_id/', + }, + after: [ + { on: 'outent', field: 'ticket_group_id', set: { query: 'ticket_group_id' } } + ] + }, + save: { + request: { + method: 'post', + path: '/ticket_groups/:ticket_group_id/', + body: { + ticket_group: [ + 'name', + 'status', + 'event_ticket_ids', + ] + } + }, + after: [ + { on: 'outent', field: 'ticket_class_id', set: { inent: 'ticket_class_id' } } + ] + } + }, + }, + venue: { + actions: { + load: { + request: { + method: 'get', + path: '/venues/:venue_id/', + }, + after: [ + { on: 'outent', field: 'venue_id', set: { query: 'venue_id' } } + ] + }, + save: { + request: { + method: 'post', + path: '/venues/:venue_id/', + body: { + venue: [ + 'name', + 'capacity', + 'address', + ] + } + }, + after: [ + { on: 'outent', field: 'venue_id', set: { inent: 'venue_id' } } + ] + } + }, + }, + user: { + actions: { + load: { + request: { + method: 'get', + path: '/users/:user_id/', + }, + }, + }, + }, } export { entities } diff --git a/test/ents-tests.ts b/test/ents-tests.ts index 35dc81e..90f3bee 100644 --- a/test/ents-tests.ts +++ b/test/ents-tests.ts @@ -11,6 +11,12 @@ const test_args = { format_id: '100', event_series_id: '100', order_id: '1234', + venue_id: '1234', + user_id: '123456', + ticket_group: { + ticket_group_id: '1234', + name: 'foo' + }, ticket_class: { ticket_class_id: '1234', event_id: '238083523227', @@ -353,7 +359,60 @@ const ents_tests: TestEntityMap = { } }, } - } + }, + ticket_group: { + load: { + args: { + ticket_group_id: test_args.ticket_group.ticket_group_id + }, + expectations: { + name: { + sameAs: test_args.ticket_group.name + }, + }, + }, + save: { + changes: { + name: 'foo' + }, + expectations: { + name: { + sameAs: 'bar' + } + }, + } + }, + venue: { + load: { + args: { + venue_id: test_args.venue_id + }, + }, + save: { + changes: { + name: 'Foo' + }, + expectations: { + name: { + sameAs: 'Bar' + } + }, + } + }, + user: { + load: { + args: { + user_id: test_args.user_id + }, + expectations: { + user: { + toMatchObject: { + id: test_args.user_id, + } + }, + }, + } + }, } export { ents_tests } diff --git a/test/mocks.ts b/test/mocks.ts index ca0cb06..9e77637 100644 --- a/test/mocks.ts +++ b/test/mocks.ts @@ -195,6 +195,48 @@ const mocks = { } }, }, + ticket_group: { + get: { + url: "/ticket_groups/:ticket_group_id/", + mock_data: { + name: 'foo', + status: 'live', + } + }, + post: { + url: "/ticket_groups/:ticket_group_id/", + mock_data: { + name: 'bar', + status: 'live', + } + }, + }, + vanue: { + get: { + url: "/venues/:venue_id/", + mock_data: { + id: '1234', + name: 'Foo' + } + }, + post: { + url: "/venues/:venue_id/", + mock_data: { + id: '1234', + name: 'Bar' + } + }, + }, + user: { + get: { + url: "/users/:user_id/", + mock_data: { + user: { + id: '123456', + } + } + }, + }, } export { mocks } From 2f531fb94619904cc1edf946647470f863c21411 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Tue, 15 Feb 2022 11:12:31 -0300 Subject: [PATCH 09/14] Add media entity and its tests instructions --- src/entities.ts | 26 ++++++++++++++++++++++++++ test/ents-tests.ts | 21 +++++++++++++++++++++ test/mocks.ts | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) diff --git a/src/entities.ts b/src/entities.ts index 38a6cdd..183266b 100644 --- a/src/entities.ts +++ b/src/entities.ts @@ -398,6 +398,32 @@ const entities: EntityMap = { }, }, }, + media: { + actions: { + load: { + request: { + method: 'get', + path: '/media/:media_id/?width=:width&height=:height', + }, + after: [ + { on: 'outent', field: 'media_id', set: { query: 'media_id' } } + ] + }, + save: { + request: { + method: 'post', + path: '/media/:media_id/?width=:width&height=:height', + body: [ + 'upload_token', + 'crop_mask' + ] + }, + after: [ + { on: 'outent', field: 'media_id', set: { inent: 'media_id' } } + ] + }, + }, + }, } export { entities } diff --git a/test/ents-tests.ts b/test/ents-tests.ts index 90f3bee..bd5be55 100644 --- a/test/ents-tests.ts +++ b/test/ents-tests.ts @@ -413,6 +413,27 @@ const ents_tests: TestEntityMap = { }, } }, + media: { + load: { + args: { + media_id: '207605529', + width: '10', + height: '15' + }, + }, + save: { + changes: { + crop_mask: { + top_left: { + y: 15, + x: 15, + }, + width: 123, + height: 321 + } + }, + } + }, } export { ents_tests } diff --git a/test/mocks.ts b/test/mocks.ts index 9e77637..dbad8f7 100644 --- a/test/mocks.ts +++ b/test/mocks.ts @@ -237,6 +237,38 @@ const mocks = { } }, }, + media: { + get: { + url: "/media/:media_id/", + mock_data: { + id: '207605529', + crop_mask: { + top_left: { + top_left: { + y: 15, + x: 15, + }, + width: 123, + height: 321 + } + } + } + }, + post: { + url: "/media/:media_id/", + mock_data: { + id: '207605529', + crop_mask: { + top_left: { + y: 15, + x: 15, + }, + width: 123, + height: 321 + } + } + } + }, } export { mocks } From 0e93b45d7ed2a11bfb26db5fffb9ad3d75c01ce6 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Tue, 15 Feb 2022 11:14:53 -0300 Subject: [PATCH 10/14] Create build_query() and build_path() in make-actions.ts Replace build_path() for build_uri() --- src/make-actions.ts | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/make-actions.ts b/src/make-actions.ts index c0ebca3..85e479b 100644 --- a/src/make-actions.ts +++ b/src/make-actions.ts @@ -17,7 +17,7 @@ function make_actions(action_data: ActionData) { perform_tasks(before, context) } - const built_path = build_path(path, q) + const built_path = build_uri(path, q) const res = await req_fn(built_path) @@ -38,7 +38,7 @@ function make_actions(action_data: ActionData) { const { q, ent } = msg let body: Record = {} - const built_path = build_path(path, ent) + const built_path = build_uri(path, ent) if(action_data.details.request.body) { body = fill_body(action_data.details.request.body, ent) @@ -83,6 +83,19 @@ function make_actions(action_data: ActionData) { return body } + function build_uri(str: string, args: Record) { + let query = '' + let [ uri_blueprint, query_blueprint ] = str.split('?') + + if(query_blueprint) { + query = build_query(query_blueprint, args) + } + + const uri = build_path(uri_blueprint, args) + + return query ? uri + '?' + query : uri + } + function build_path(path: string, args: Record) { const placeholders = path .split("/") @@ -96,6 +109,18 @@ function make_actions(action_data: ActionData) { return path } + function build_query(str: string, args: Record) { + const params = str.split('&') + + return params.map(p => { + const param_name = p.split(":")[1] + + if(args[param_name]) { + return p.replace(':' + param_name, args[param_name]) + } + }).filter(x => x !== undefined).join('&') + } + return { load, save From d2c161d2b433c23351d176fe7abf7b27416c522f Mon Sep 17 00:00:00 2001 From: Gustavo Date: Tue, 15 Feb 2022 11:16:01 -0300 Subject: [PATCH 11/14] Change type of body attr in ReqDetails --- src/make-actions.ts | 11 ++++++++++- src/types.ts | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/make-actions.ts b/src/make-actions.ts index 85e479b..7cfb139 100644 --- a/src/make-actions.ts +++ b/src/make-actions.ts @@ -71,8 +71,17 @@ function make_actions(action_data: ActionData) { return outent } - function fill_body(body_specs: Record>, entity: Record) { + function fill_body(body_specs: Array | Record>, entity: Record) { let body: Record = {} + + if(Array.isArray(body_specs)) { + body_specs.forEach(attr => { + body[attr] = entity[attr] + }) + + return body + } + for(const [key, body_args] of Object.entries(body_specs)) { body[key] = {} body_args.forEach(attr => { diff --git a/src/types.ts b/src/types.ts index d52474f..a1884f8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -7,7 +7,7 @@ type Actions = "load" | "save" type ReqDetails = { method: string path: string - body?: Record> + body?: Array | Record> } type TasksTypes = SetTask | DelTask From 4b5b91f26cd32448c13170d1aada926ceb0cfc8e Mon Sep 17 00:00:00 2001 From: Gustavo Date: Tue, 15 Feb 2022 11:16:54 -0300 Subject: [PATCH 12/14] Refactor urls in mocks.ts Remove query --- test/mocks.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/mocks.ts b/test/mocks.ts index dbad8f7..45daf29 100644 --- a/test/mocks.ts +++ b/test/mocks.ts @@ -133,7 +133,7 @@ const mocks = { }, sales_report: { get: { - url: "/reports/sales?event_ids=:event_ids&event_status=:event_status&start_date=:start_date&end_date=:end_date&filter_by=:filter_by&group_by=:group_by&period=:period&date_facet=:date_facet&timezone=:timezoney", + url: "/reports/sales", mock_data: { id: '1234', } @@ -141,7 +141,7 @@ const mocks = { }, attendee_report: { get: { - url: "/reports/attendees?event_ids=:event_ids&event_status=:event_status&start_date=:start_date&end_date=:end_date&filter_by=:filter_by&group_by=:group_by&period=:period&date_facet=:date_facet&timezone=:timezoney", + url: "/reports/attendees", mock_data: { id: '1234', } @@ -149,7 +149,7 @@ const mocks = { }, published_structured_content: { get: { - url: "/events/:id/structured_content?propose=:propose", + url: "/events/:id/structured_content", mock_data: { access_type: 'public', } @@ -157,7 +157,7 @@ const mocks = { }, working_structured_content: { get: { - url: "/events/:id/structured_content/edit?propose=:propose", + url: "/events/:id/structured_content/edit", mock_data: { access_type: 'public', } @@ -165,7 +165,7 @@ const mocks = { }, text_overrides: { get: { - url: "/organizations/:organization_id/text_overrides/?locale=:locale&venue_id=:venue_id&event_id=:event_id&text_codes=:text_codes", + url: "/organizations/:organization_id/text_overrides", mock_data: { text_code: 'tickets_not_yet_on_sale', } From cbbffca7d6adaa139c05131753a3115f71902097 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Tue, 15 Feb 2022 11:18:01 -0300 Subject: [PATCH 13/14] Add attributes to test args in ents-tests.ts --- test/ents-tests.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/ents-tests.ts b/test/ents-tests.ts index bd5be55..c7ddb81 100644 --- a/test/ents-tests.ts +++ b/test/ents-tests.ts @@ -288,7 +288,8 @@ const ents_tests: TestEntityMap = { published_structured_content: { load: { args: { - id: 1 + id: 1, + propose: 'foo' }, expectations: { access_type: { @@ -300,7 +301,8 @@ const ents_tests: TestEntityMap = { working_structured_content: { load: { args: { - id: 1 + id: 1, + propose: 'foo' }, expectations: { access_type: { From 29784b46a59f9c5861858305fcb7da520b024005 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Tue, 15 Feb 2022 12:16:31 -0300 Subject: [PATCH 14/14] Remove trailing whitespace --- test/eventbrite-provider.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/eventbrite-provider.test.ts b/test/eventbrite-provider.test.ts index dd86027..4af1eb0 100644 --- a/test/eventbrite-provider.test.ts +++ b/test/eventbrite-provider.test.ts @@ -111,7 +111,7 @@ describe('eventbrite-provider', () => { .use("entity") .use("provider", providerOptions) .use(EventbriteProvider) - + const load_test_data = test_data.load let res_data = await seneca.entity("provider/eventbrite/" + ent_name).load$(load_test_data.args)