Skip to content

Commit

Permalink
fix: 🐛 Fake data included through ts
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanObrink committed Jan 7, 2021
1 parent 23ce095 commit 663be5c
Show file tree
Hide file tree
Showing 3 changed files with 1,057 additions and 1,034 deletions.
33 changes: 9 additions & 24 deletions lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,7 @@ import {
import * as routes from './routes'
import * as parse from './parse'
import wrap, { Fetcher, FetcherOptions } from './fetcher'

interface FakeData {
user: User
children: Child[]
data: {
[id: string]: {
classmates: Classmate[],
news: NewsItem[],
calendar: CalendarItem[],
schedule: ScheduleItem[],
menu: MenuItem[],
notifications: Notification[],
}
}
}
const fakeData: FakeData = require('./output.json')
import * as fake from './fakeData'

export class Api extends EventEmitter {
private fetch: Fetcher
Expand Down Expand Up @@ -103,7 +88,7 @@ export class Api extends EventEmitter {
}

async getUser(): Promise<User> {
if (this.isFake) return fakeData.user
if (this.isFake) return fake.user()

const url = routes.user
const response = await this.fetch('user', url, this.session)
Expand All @@ -112,7 +97,7 @@ export class Api extends EventEmitter {
}

async getChildren(): Promise<Child[]> {
if (this.isFake) return fakeData.children
if (this.isFake) return fake.children()

const url = routes.children
const response = await this.fetch('children', url, this.session)
Expand All @@ -121,7 +106,7 @@ export class Api extends EventEmitter {
}

async getCalendar(child: Child): Promise<CalendarItem[]> {
if (this.isFake) return fakeData.data[child.id].calendar
if (this.isFake) return fake.calendar(child)

const url = routes.calendar(child.id)
const response = await this.fetch('calendar', url, this.session)
Expand All @@ -130,7 +115,7 @@ export class Api extends EventEmitter {
}

async getClassmates(child: Child): Promise<Classmate[]> {
if (this.isFake) return fakeData.data[child.id].classmates
if (this.isFake) return fake.classmates(child)

const url = routes.classmates(child.sdsId)
const response = await this.fetch('classmates', url, this.session)
Expand All @@ -139,7 +124,7 @@ export class Api extends EventEmitter {
}

async getSchedule(child: Child, from: DateTime, to: DateTime): Promise<ScheduleItem[]> {
if (this.isFake) return fakeData.data[child.id].schedule
if (this.isFake) return fake.schedule(child)

const url = routes.schedule(child.sdsId, from.toISODate(), to.toISODate())
const response = await this.fetch('schedule', url, this.session)
Expand All @@ -148,7 +133,7 @@ export class Api extends EventEmitter {
}

async getNews(child: Child): Promise<NewsItem[]> {
if (this.isFake) return fakeData.data[child.id].news
if (this.isFake) return fake.news(child)

const url = routes.news(child.id)
const response = await this.fetch('news', url, this.session)
Expand All @@ -157,7 +142,7 @@ export class Api extends EventEmitter {
}

async getMenu(child: Child): Promise<MenuItem[]> {
if (this.isFake) return fakeData.data[child.id].menu
if (this.isFake) return fake.menu(child)

const url = routes.menu(child.id)
const response = await this.fetch('menu', url, this.session)
Expand All @@ -166,7 +151,7 @@ export class Api extends EventEmitter {
}

async getNotifications(child: Child): Promise<Notification[]> {
if (this.isFake) return fakeData.data[child.id].notifications
if (this.isFake) return fake.notifications(child)

const url = routes.notifications(child.sdsId)
const response = await this.fetch('notifications', url, this.session)
Expand Down
Loading

0 comments on commit 663be5c

Please sign in to comment.