Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export {
export { scrapeElections } from "./legislators"

export { transcriptionV2 } from "./webhooks"
export { scrapeHouseRollCalls, scrapeSenateRollCalls } from "./votes"

export { matchOcpfMembersV2 } from "./ocpf/matchOcpfMembers"
export { scrapeOcpfFinanceV2 } from "./ocpf/scrapeOcpfFinance"
Expand Down
26 changes: 25 additions & 1 deletion functions/src/malegislature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import {
SessionContent,
SpecialEventContent
} from "./events/types"
import { APIDocument, APIRollCall } from "./votes/types"
import { Timestamp } from "./firebase"
import { MemberContent } from "./members/types"
import { RollCallSummary } from "./votes/types"

/**
* The MA Legislature website's SSL certificate only contains the first
Expand Down Expand Up @@ -91,7 +93,7 @@ export async function getDocument({
}: {
id: string
court: number
}): Promise<any> {
}): Promise<APIDocument> {
const response = await request({
url: `/GeneralCourts/${court}/Documents/${id}`,
method: "GET",
Expand Down Expand Up @@ -250,3 +252,25 @@ export async function getSimilarBills(court: number, id: string) {
})
return SimilarBills.check(data)
}

export async function getRollCalls(court: number, branch: string) {
const data = await request({
url: `GeneralCourts/${court}/Branches/${branch}/RollCalls`,
method: "GET",
timeout: 60_000
})
return Array(RollCallSummary).check(data)
}

export async function getRollCall(
court: number,
branch: string,
number: number
): Promise<APIRollCall> {
const data = await request({
url: `GeneralCourts/${court}/Branches/${branch}/RollCalls/${number}`,
method: "GET",
timeout: 60_000
})
return APIRollCall.check(data)
}
6 changes: 6 additions & 0 deletions functions/src/votes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export {
scrapeHouseRollCalls,
scrapeSenateRollCalls,
HouseRollCallScraper,
SenateRollCallScraper
} from "./scrapers"
51 changes: 51 additions & 0 deletions functions/src/votes/scrapeRollCall.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {
getHouseRollCall,
HouseRollCallResult,
translateNames
} from "./scrapeRollCall"

import fs from "fs"
import path from "path"

const FIXTURES_DIR = path.resolve(__dirname, "../../../tests/fixtures/votes")

const pdf = fs.readFileSync(path.join(FIXTURES_DIR, "HouseRollCall19.pdf"))

global.fetch = jest.fn().mockResolvedValue({
ok: true,
status: 200,
arrayBuffer: async () =>
pdf.buffer.slice(pdf.byteOffset, pdf.byteOffset + pdf.byteLength)
}) as jest.Mock

describe("getHouseRollCall test", () => {
it("HouseRollCall19", async () => {
const legislators_file = fs.readFileSync(
path.join(FIXTURES_DIR, "193legislators.json"),
"utf8"
)
const legislators: [string, string][] = JSON.parse(legislators_file)

const actualRead = await getHouseRollCall(193, 19)
const expectedRead = JSON.parse(
fs.readFileSync(
path.join(FIXTURES_DIR, "HouseRollCall19Read.json"),
"utf8"
)
)
expectedRead.time = new Date(expectedRead.time)
expect(actualRead).toEqual(expectedRead)
const expectedTranslation = JSON.parse(
fs.readFileSync(
path.join(FIXTURES_DIR, "HouseRollCall19Translation.json"),
"utf8"
)
)
const read = <HouseRollCallResult>actualRead
const names = read.votes.map(
vote => [vote.initial, vote.lastName] as [string | null, string]
)
const actualTranslation = translateNames(names, legislators)
expect(actualTranslation).toEqual(expectedTranslation)
})
})
Loading
Loading