Skip to content

Commit

Permalink
delete changes in sportsdataio, fix problem with integrationt test
Browse files Browse the repository at this point in the history
  • Loading branch information
bogos committed Feb 8, 2022
1 parent 50bb30e commit 2938973
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 70 deletions.
53 changes: 39 additions & 14 deletions packages/sources/sportsdataio/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
import { Builder } from '@chainlink/ea-bootstrap'
import {
Config,
ExecuteWithConfig,
ExecuteFactory,
AdapterRequest,
APIEndpoint,
} from '@chainlink/types'
import { makeConfig } from './config'
import * as endpoints from './endpoint'
import { Requester, Validator, AdapterError } from '@chainlink/ea-bootstrap'
import { Config, ExecuteWithConfig, ExecuteFactory } from '@chainlink/types'
import { makeConfig, DEFAULT_SPORT } from './config'
import { MMA, NFL, NCAA_FB, NBA, MLB } from './sport'

export const execute: ExecuteWithConfig<Config> = async (request, context, config) => {
return Builder.buildSelector(request, context, config, endpoints)
const inputParams = {
sport: true,
}

export const endpointSelector = (request: AdapterRequest): APIEndpoint =>
Builder.selectEndpoint(request, makeConfig(), endpoints)
export const execute: ExecuteWithConfig<Config> = async (request, context, config) => {
const validator = new Validator(request, inputParams)

Requester.logConfig(config)

const jobRunID = validator.validated.id
const sport = validator.validated.data.sport || DEFAULT_SPORT

switch (sport.toLowerCase()) {
case MMA.NAME: {
return await MMA.execute(request, context, config)
}
case NFL.NAME: {
return await NFL.execute(request, context, config)
}
case NCAA_FB.NAME: {
return await NCAA_FB.execute(request, context, config)
}
case NBA.NAME: {
return await NBA.execute(request, context, config)
}
case MLB.NAME: {
return await MLB.execute(request, context, config)
}
default: {
throw new AdapterError({
jobRunID,
message: `Sport ${sport} not supported.`,
statusCode: 400,
})
}
}
}

export const makeExecute: ExecuteFactory<Config> = (config) => {
return async (request, context) => execute(request, context, config || makeConfig())
Expand Down
2 changes: 1 addition & 1 deletion packages/sources/sportsdataio/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ export const makeConfig = (prefix?: string): Config => {
mlbKey: util.getEnv(ENV_MLB_API_KEY, prefix),
}
config.api.baseURL = config.api.baseURL || DEFAULT_BASE_URL
config.defaultEndpoint = DEFAULT_ENDPOINT

return config
}
1 change: 0 additions & 1 deletion packages/sources/sportsdataio/src/endpoint/index.ts

This file was deleted.

49 changes: 0 additions & 49 deletions packages/sources/sportsdataio/src/endpoint/scores.ts

This file was deleted.

7 changes: 3 additions & 4 deletions packages/sources/sportsdataio/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expose } from '@chainlink/ea-bootstrap'
import { makeExecute, endpointSelector } from './adapter'
import { makeExecute } from './adapter'
import { makeConfig, NAME } from './config'
import * as types from './endpoint'

const { server } = expose(NAME, makeExecute(), undefined, endpointSelector)
export { NAME, makeExecute, makeConfig, server, types }
const { server } = expose(NAME, makeExecute())
export { NAME, makeExecute, makeConfig, server }
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { AdapterRequest } from '@chainlink/types'
import request from 'supertest'
import request, { SuperTest, Test } from 'supertest'
import process from 'process'
import nock from 'nock'
import http from 'http'
import { server as startServer } from '../../../src'
import { mockGamesResponse } from './fixtures'
import { AddressInfo } from 'net'

let oldEnv: NodeJS.ProcessEnv

Expand Down

0 comments on commit 2938973

Please sign in to comment.