Skip to content

Commit

Permalink
Merge pull request #29 from JHWelch/enable-max-len
Browse files Browse the repository at this point in the history
Enable max-len rule
  • Loading branch information
JHWelch authored Aug 12, 2023
2 parents e11ce53 + 4387f17 commit 31a33fc
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 168 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ module.exports = {
'comma-dangle': ['error', 'always-multiline'],
'no-console': ['error', { allow: ['warn', 'error'] }],
indent: ['error', 2],
'max-len': ['error', {
ignoreStrings: true,
ignoreTrailingComments: true,
ignoreUrls: true,
tabWidth: 2,
}],
'object-curly-spacing': ['error', 'always'],
quotes: ['error', 'single'],
semi: ['error', 'never'],
Expand Down
20 changes: 9 additions & 11 deletions __tests__/controllers/cacheController.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ let notionMock: NotionMock

const { res, mockClear } = getMockRes()

const newCacheController = () => {
const firestore = new FirestoreAdapter()
const notion = new NotionAdapter()
const tmdbAdapter = new TmdbAdapter()
return new CacheController(firestore, notion, tmdbAdapter)
}

beforeAll(() => {
jest.mock('@notionhq/client')
jest.mock('firebase-admin/app')
Expand All @@ -34,9 +41,6 @@ beforeEach(() => {
})

describe('cache', () => {
let firestore: FirestoreAdapter
let notion: NotionAdapter
let tmdbAdapter: TmdbAdapter
let req: Request

describe('when the cache is empty', () => {
Expand All @@ -47,14 +51,11 @@ describe('cache', () => {
NotionMock.mockWeek('id2', '2021-01-08', 'theme2'),
NotionMock.mockWeek('id3', '2021-01-15', 'theme3'),
])
firestore = new FirestoreAdapter()
notion = new NotionAdapter()
tmdbAdapter = new TmdbAdapter()
req = getMockReq()
})

it('updates all weeks in firestore', async () => {
const cacheController = new CacheController(firestore, notion, tmdbAdapter)
const cacheController = newCacheController()

await cacheController.cache(req, res)

Expand Down Expand Up @@ -107,17 +108,14 @@ describe('cache', () => {
NotionMock.mockWeek('id1', '2021-01-01', 'theme1', false, [notionResponse]),
])
notionMock.mockRetrieve(notionResponse)
firestore = new FirestoreAdapter()
notion = new NotionAdapter()
tmdbAdapter = new TmdbAdapter()
req = getMockReq()
const tmdbMock = new TmdbMock(mockFetch())
tmdbMock.mockSearchMovie(tmdb)
tmdbMock.mockMovieDetails(tmdb)
})

it('stores data from tmdb in firestore', async () => {
const cacheController = new CacheController(firestore, notion, tmdbAdapter)
const cacheController = newCacheController()

await cacheController.cache(req, res)

Expand Down
9 changes: 7 additions & 2 deletions __tests__/support/fetchMock.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { jest } from '@jest/globals'

export type MockFetch = jest.Mock<(input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response>>
type FetchFunction = (
input: RequestInfo | URL,
init?: RequestInit | undefined
) => Promise<Response>;

export type MockFetch = jest.Mock<FetchFunction>

export function mockFetch (): MockFetch {
const mockFetch = jest.fn<(input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response>>()
const mockFetch = jest.fn<FetchFunction>()
global.fetch = mockFetch

return mockFetch
Expand Down
8 changes: 6 additions & 2 deletions __tests__/support/notionMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export class NotionMock {
mockRetrieve = (movie: NotionMovie | undefined = undefined) => {
const notionMovie = movie ?? NotionMovie.demo()

this.retrieve.mockImplementation(async (args: WithAuth<GetPageParameters>): Promise<GetPageResponse> => {
this.retrieve.mockImplementation(async (
args: WithAuth<GetPageParameters>
): Promise<GetPageResponse> => {
const { page_id } = args as { page_id: string }

if (page_id !== notionMovie.id) {
Expand All @@ -45,7 +47,9 @@ export class NotionMock {

mockQuery = (weeks: PageObjectResponse[] = []) => {
this.query.mockImplementation(
async (_args: WithAuth<QueryDatabaseParameters>): Promise<QueryDatabaseResponse> => ({
async (
_args: WithAuth<QueryDatabaseParameters>
): Promise<QueryDatabaseResponse> => ({
page_or_database: {},
type: 'page_or_database',
object: 'list',
Expand Down
Loading

0 comments on commit 31a33fc

Please sign in to comment.