Skip to content

Commit

Permalink
[ag|#1] add phone parsing logic to parsing service
Browse files Browse the repository at this point in the history
side-effects:

* add phone numbers to fixtures
* provide mock responses for phone number API requests
  • Loading branch information
aguestuser committed Jun 20, 2018
1 parent 90c4b8e commit c7e95f3
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 19 deletions.
19 changes: 17 additions & 2 deletions src/service/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {lowerFirst} from "lodash"
export const parseVanEvents = (akes: ActionKitEvent[]): VanEvent[] =>
akes.map(parseVanEvent)

export const parseVanEvent = (ake: ActionKitEvent): VanEvent => ({
const parseVanEvent = (ake: ActionKitEvent): VanEvent => ({
actionKitId: ake.id,
name: ake.title,
description: ake.public_description,
Expand Down Expand Up @@ -71,5 +71,20 @@ const parseVanPerson = (akp: ActionKitPerson): VanPerson => ({
suffix: akp.suffix,
addresses: [parseVanAddress(akp, "Home")],
emails: [{ email: akp.email, type: "P" }],
phones: [],
phones: parseVanPhones(akp.phones),
})

const parseVanPhones = (akphs: ActionKitPhone[]): VanPhone[] =>
akphs.map(parseVanPhone)

const parseVanPhone = (akph: ActionKitPhone): VanPhone => ({
actionKitId: akph.id,
phoneNumber: akph.normalized_phone,
phoneType: {
home: "H",
work: "W",
mobile: "M",
home_fax: "F",
mobile_fax: "F",
}[akph.type] || "M",
})
4 changes: 2 additions & 2 deletions src/types/ActionKitPhone.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
declare interface ActionKitPhone {
created_at: Date,
created_at: Date | string,
id: number,
normalized_phone: string,
phone: string,
resource_uri: string,
source: string,
type: ActionKitPhoneType
updated_at: Date,
updated_at: Date | string,
user: string // ActionKitPerson
}

Expand Down
7 changes: 6 additions & 1 deletion src/types/VanPhone.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
declare interface VanPhone {
/////////////
actionKitId?: number,
vanId?: number,
id?: number,
/////////////
phoneNumber: string,
phoneType?: "H" | "W" | "C" | "M" | "F"
ext?: string,
isPreferred?: string,
isPreferred?: boolean,
phoneOptInStatus?: string,
}
29 changes: 28 additions & 1 deletion test/fixtures/Responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ export const userResponseAttendee: ActionKitPersonResponse = {
middle_name: "",
orderrecurrings: "/rest/v1/orderrecurring/?user=350568",
orders: "/rest/v1/order/?user=350568",
phones: [],
phones: [
"/rest/v1/phone/568/",
"/rest/v1/phone/569/",
],
plus4: "",
postal: "11213",
prefix: "",
Expand All @@ -185,6 +188,30 @@ export const userResponseAttendee: ActionKitPersonResponse = {
zip: "11213",
}

export const phoneResponseAttendeeHome = {
created_at: "2018-06-12T20:13:49",
id: 568,
normalized_phone: "6151234567",
phone: "6151234567",
resource_uri: "/rest/v1/phone/568/",
source: "user",
type: "home",
updated_at: "2018-06-12T20:13:49",
user: "/rest/v1/user/350568/",
}

export const phoneResponseAttendeeMobile = {
created_at: "2018-06-12T20:15:11",
id: 569,
normalized_phone: "3041234567",
phone: "+1-304-123-4567",
resource_uri: "/rest/v1/phone/569/",
source: "user",
type: "mobile",
updated_at: "2018-06-12T20:15:11",
user: "/rest/v1/user/350568/",
}

export const userResponseHost: ActionKitPersonResponse = {
actions: "/rest/v1/action/?user=350567",
address1: "",
Expand Down
25 changes: 24 additions & 1 deletion test/fixtures/actionKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,30 @@ export const actionKitEventTree: ActionKitEvent[] = [
lang: "/rest/v1/language/100/",
last_name: "Guy",
middle_name: "",
phones: [],
phones: [
{
created_at: "2018-06-12T20:13:49",
id: 568,
normalized_phone: "6151234567",
phone: "6151234567",
resource_uri: "/rest/v1/phone/568/",
source: "user",
type: "home",
updated_at: "2018-06-12T20:13:49",
user: "/rest/v1/user/350568/",
},
{
created_at: "2018-06-12T20:15:11",
id: 569,
normalized_phone: "3041234567",
phone: "+1-304-123-4567",
resource_uri: "/rest/v1/phone/569/",
source: "user",
type: "mobile",
updated_at: "2018-06-12T20:15:11",
user: "/rest/v1/user/350568/",
},
],
plus4: "",
postal: "11213",
prefix: "",
Expand Down
10 changes: 9 additions & 1 deletion test/fixtures/van.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ export const vanEventTree: VanEvent[] = [
email: "[email protected]",
type: "P",
}],
phones: [],
phones: [{
actionKitId: 568,
phoneNumber: "6151234567",
phoneType: "H",
}, {
actionKitId: 569,
phoneNumber: "3041234567",
phoneType: "M",
}],
// region: "",
// source: "website",
},
Expand Down
19 changes: 9 additions & 10 deletions test/service/ActionKitAPI.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {expect} from "chai"
import {describe, it, before} from "mocha"
import * as nock from "nock"
import {getEvents, getEventSignup, getUser} from "../../src/service/ActionKitAPI"
import * as responses from "../fixtures/Responses"

describe("ActionKitAPI", () => {
before(() => {
nock("https://roboticdogs.actionkit.com" )
nock("https://roboticdogs.actionkit.com")
.persist()
.get("/rest/v1/event/?campaign=289")
.reply(200, responses.eventsResponse)
Expand All @@ -21,8 +22,14 @@ describe("ActionKitAPI", () => {
.reply(200, responses.userResponseHost)
.get("/rest/v1/user/350568/")
.reply(200, responses.userResponseAttendee)
.get("/rest/v1/phone/568")
.reply(200, responses.phoneResponseAttendeeHome)
.get("/rest/v1/phone/569")
.reply(200, responses.phoneResponseAttendeeMobile)
})

// TODO: expand test coverage, esp: for pagination

describe("getEvents", () => {
it("contains the events for the campaign", async () => {
const events = await getEvents("/rest/v1/event/?campaign=289")
Expand All @@ -44,15 +51,7 @@ describe("ActionKitAPI", () => {
})
})

describe("createStreams", () => {
it("creates streams", (done) => {
done()
})
})

describe("sync", () => {
it("runs rxjs", (done) => {
done()
})
it("syncs all resources")
})
})
2 changes: 1 addition & 1 deletion test/service/parse.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {expect} from "chai"
import {describe, it} from "mocha"
import {parseVanEvent, parseVanEvents} from "../../src/service/parse"
import {parseVanEvents} from "../../src/service/parse"
import {actionKitEventTree} from "../fixtures/actionKit"
import {vanEventTree} from "../fixtures/van"

Expand Down

0 comments on commit c7e95f3

Please sign in to comment.