feat: 🎸 Removed getImage() and added .fullImageUrl to NewsItem (#33)

BREAKING CHANGE: 🧨 api no longer exposes getImage()
This commit is contained in:
Johan Öbrink 2021-01-05 14:09:11 +01:00 committed by GitHub
parent 6edb98c974
commit 5c3929d9d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 4 additions and 36 deletions

View File

@ -12,7 +12,6 @@ describe('api', () => {
response = {
json: jest.fn(),
text: jest.fn(),
blob: jest.fn(),
ok: true,
status: 200,
statusText: 'ok',

View File

@ -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()

View File

@ -18,7 +18,6 @@ describe('fetcher', () => {
statusText: 'ok',
json: jest.fn(),
text: jest.fn(),
blob: jest.fn(),
headers,
}
fetch = jest.fn().mockResolvedValue(response)
@ -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
@ -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)
})
})
})

View File

@ -67,7 +67,6 @@ export default function wrap(fetch: Fetch, options: FetcherOptions = {}): Fetche
}
wrapMethod(response, 'json')
wrapMethod(response, 'text')
wrapMethod(response, 'blob')
return response
}

View File

@ -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')

View File

@ -78,6 +78,7 @@ 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 => ({
@ -85,6 +86,7 @@ export const newsItem = ({
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(),

View File

@ -17,7 +17,6 @@ export interface Response {
statusText: string
text: () => Promise<string>
json: () => Promise<any>
blob: () => Promise<Blob>
}
export interface Fetch {
@ -102,6 +101,7 @@ export interface NewsItem {
published: string
modified?: string
imageUrl?: string
fullImageUrl?: string
}
/**

7
run.js
View File

@ -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)