Skip to content

Commit

Permalink
feat: 🎸 Removed getImage() and added .fullImageUrl to NewsItem (kolpl…
Browse files Browse the repository at this point in the history
…attformen#33)

BREAKING CHANGE: 🧨 api no longer exposes getImage()
  • Loading branch information
JohanObrink authored Jan 5, 2021
1 parent 6edb98c commit 5c3929d
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 36 deletions.
1 change: 0 additions & 1 deletion lib/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ describe('api', () => {
response = {
json: jest.fn(),
text: jest.fn(),
blob: jest.fn(),
ok: true,
status: 200,
statusText: 'ok',
Expand Down
6 changes: 0 additions & 6 deletions lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,6 @@ export class Api extends EventEmitter {
return parse.notifications(data)
}

async getImage(imageUrl: string): Promise<Blob> {
const response = await this.fetch('image', imageUrl, this.session)
const data = await response.blob()
return data
}

async logout() {
this.session = undefined
await this.clearCookies()
Expand Down
20 changes: 0 additions & 20 deletions lib/fetcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe('fetcher', () => {
statusText: 'ok',
json: jest.fn(),
text: jest.fn(),
blob: jest.fn(),
headers,
}
fetch = jest.fn().mockResolvedValue(response)
Expand Down Expand Up @@ -46,15 +45,6 @@ describe('fetcher', () => {

expect(result).toEqual(data)
})
it('blob returns the result', async () => {
const data = new Blob()
response.blob.mockResolvedValue(data)

const res = await fetcher('foo', '/')
const result = await res.blob()

expect(result).toEqual(data)
})
describe('record', () => {
let recorder: Recorder
let expectedInfo: CallInfo
Expand Down Expand Up @@ -89,15 +79,5 @@ describe('fetcher', () => {
const expectedData = 'Hello'
expect(recorder).toHaveBeenCalledWith(expectedInfo, expectedData)
})
it('records with the correct parameters for blob', async () => {
const data = new Blob('Hello')
response.blob.mockResolvedValue(data)

await (await fetcher('foo', '/')).blob()

expectedInfo.type = 'blob'

expect(recorder).toHaveBeenCalledWith(expectedInfo, data)
})
})
})
1 change: 0 additions & 1 deletion lib/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export default function wrap(fetch: Fetch, options: FetcherOptions = {}): Fetche
}
wrapMethod(response, 'json')
wrapMethod(response, 'text')
wrapMethod(response, 'blob')

return response
}
Expand Down
1 change: 1 addition & 0 deletions lib/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ describe('parse', () => {
expect(item.id).toEqual('news id')
expect(item.header).toEqual('Problemet med att se betyg i bild, slöjd och teknik löst!')
expect(item.imageUrl).toEqual('A703552D-DBF3-45B0-8E67-6E062105A0C5.jpeg')
expect(item.fullImageUrl).toEqual('https://etjanst.stockholm.se/Vardnadshavare/inloggad2/NewsBanner?url=A703552D-DBF3-45B0-8E67-6E062105A0C5.jpeg')
expect(item.intro).toEqual('Hej,Nu är problemet löst! Alla betyg syns som de ska.God jul!...')
expect(item.modified).toEqual('2020-12-18T16:18:00.000+01:00')
expect(item.published).toEqual('2020-12-18T16:15:00.000+01:00')
Expand Down
2 changes: 2 additions & 0 deletions lib/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ export const calendarItem = ({
})
export const calendar = (data: any): CalendarItem[] => etjanst(data).map(calendarItem)

const IMAGE_HOST = 'https://etjanst.stockholm.se/Vardnadshavare/inloggad2/NewsBanner?url='
export const newsItem = ({
newsId, header, preamble, body, bannerImageUrl, pubDateSe, modDateSe,
}: any): NewsItem => ({
header,
id: newsId,
intro: preamble,
imageUrl: bannerImageUrl,
fullImageUrl: `${IMAGE_HOST}${bannerImageUrl}`,
body: htmlDecode(h2m(body)),
published: DateTime.fromFormat(pubDateSe, 'dd LLLL yyyy HH:mm', dateTimeOptions).toISO(),
modified: DateTime.fromFormat(modDateSe, 'dd LLLL yyyy HH:mm', dateTimeOptions).toISO(),
Expand Down
2 changes: 1 addition & 1 deletion lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export interface Response {
statusText: string
text: () => Promise<string>
json: () => Promise<any>
blob: () => Promise<Blob>
}

export interface Fetch {
Expand Down Expand Up @@ -102,6 +101,7 @@ export interface NewsItem {
published: string
modified?: string
imageUrl?: string
fullImageUrl?: string
}

/**
Expand Down
7 changes: 0 additions & 7 deletions run.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ async function run() {
const news = await api.getNews(children[0])
// console.log(news)

// console.log('image')
// const blob = await api.getImage(news[0].imageUrl)
// console.log(blob)

// const arrayBuffer = await blob.arrayBuffer()
// console.log(`data:${blob.type};base64,${Buffer.from(arrayBuffer).toString('base64')}`)

console.log('menu')
const menu = await api.getMenu(children[0])
// console.log(menu)
Expand Down

0 comments on commit 5c3929d

Please sign in to comment.