Skip to content

Commit

Permalink
Merge pull request #3 from data-depot/staging
Browse files Browse the repository at this point in the history
chore: release v0.0.1
  • Loading branch information
Walee Ahmed authored Apr 30, 2020
2 parents b974422 + 9d35d39 commit 10418dc
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 51 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ jobs:
run: yarn test --ci --coverage --maxWorkers=2
env:
CI: true
APP_TOKEN: ${{ secrets.OPEN_DATA_APP_TOKEN }}

- name: Coverage
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage/clover.xml

- name: Build
run: yarn build
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
node_modules
dist
.env
coverage/
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@thinkempirenyc:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=PERSONAL_GITHUB_ACCESS_TOKEN
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# soda-ts

[![codecov](https://codecov.io/gh/data-depot/soda-ts/branch/staging/graph/badge.svg?token=6996L6JATW)](https://codecov.io/gh/data-depot/soda-ts)

## A simple library to interact with open data
File renamed without changes.
11 changes: 10 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node'
testEnvironment: 'node',
setupFilesAfterEnv: ['./config/testSetup.ts'],
coverageThreshold: {
global: {
branches: 80,
functions: 90,
lines: 90,
statements: 90
}
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"start": "tsdx watch",
"build": "tsdx build",
"test": "tsdx test",
"test:watch": "tsdx test --watch",
"test:coverage": "tsdx test --coverage",
"lint": "tsdx lint src test",
"lint:fix": "yarn lint --fix",
"prepare": "tsdx build"
Expand Down
2 changes: 1 addition & 1 deletion src/clauses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export const clauseTransformer = (
): URLReqParams => [clause.name, clause.value]

/**
* transform clauses in query into consumption in `URLParams`
*
* @param clauses takes clauses from query object
*
* @returns `GotReqParams[]` which are directly passed
*/
export const queryClauseTransformer = (
Expand Down
1 change: 0 additions & 1 deletion src/createRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export const createRunner = <T>(
.json<T[]>()
return res
} catch (e) {
console.error(e)
throw new Error(e.message)
}
}
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import './env'

export * from './clauses'
export * from './createRunner'
export * from './query'
Expand Down
1 change: 1 addition & 0 deletions src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const createQuery = (
const domain =
queryOpts?.domain ?? 'data.cityofnewyork.us'
const apiPath = queryOpts?.apiPath ?? 'resource'

return {
src,
domain,
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface Query {
domain: string
/** clauses to run w/ the query */
clauses: Array<Clause> | []
// TODO: refactor into enum
/** rest path associated with api and domain */
apiPath: 'resource' | 'api/views' | 'api/catalog/v1'
}
Expand Down
46 changes: 0 additions & 46 deletions test/clauses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,13 @@ import {
createQuery,
createClause,
Query,
createRunner,
clauseTransformer,
queryClauseTransformer,
Clause
} from '../src'

const SRC = 'w7w3-xahh'
const DOMAIN = 'data.cityofnewyork.us'
const CLAUSE = 'test'

describe('query', () => {
it('queryCreator', () => {
const query = createQuery(SRC)

expect(query).toStrictEqual({
src: SRC,
domain: DOMAIN,
apiPath: 'resource',
clauses: []
})
})
})

describe('createRunner', () => {
let query: Query
let runner: ReturnType<typeof createRunner>

const authOpts = {
appToken: process.env.APP_TOKEN
}

let authenticatedRunner: ReturnType<typeof createRunner>

beforeAll(() => {
query = createQuery('w7w3-xahh')
runner = createRunner()
authenticatedRunner = createRunner(authOpts)
})

it('successfully grabs ', async () => {
const res = await runner(query)

expect(res.length).toBeGreaterThan(1)
})

it('successfully grabs with authentication ', async () => {
// TODO: add support for .env in CI/CD
// expect(authOpts.appToken).not.toBeUndefined()
const res = await authenticatedRunner(query)
expect(res.length).toBeGreaterThan(1)
})
})

describe('clauses', () => {
let query: Query

Expand Down
46 changes: 46 additions & 0 deletions test/query.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { createQuery } from '../src'

const SRC = 'w7w3-xahh'
const DOMAIN = 'data.cityofnewyork.us'

describe('query', () => {
it('queryCreator', () => {
const query = createQuery(SRC)

expect(query).toStrictEqual({
src: SRC,
domain: DOMAIN,
apiPath: 'resource',
clauses: []
})
})

it('custom domain', () => {
const DOMAIN = 'test.test.nyc'
const query = createQuery(SRC, {
domain: DOMAIN
})

expect(query.domain).toBe(DOMAIN)
})

it('default domain', () => {
const query = createQuery(SRC)

expect(query.domain).toBe('data.cityofnewyork.us')
})

it('default api path', () => {
const query = createQuery(SRC)

expect(query.apiPath).toBe('resource')
})

it('set api path', () => {
const query = createQuery(SRC, {
apiPath: 'api/catalog/v1'
})

expect(query.apiPath).toBe('api/catalog/v1')
})
})
40 changes: 40 additions & 0 deletions test/runner.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { createRunner, createQuery, Query } from '../src'

describe('createRunner', () => {
let query: Query
let runner: ReturnType<typeof createRunner>

const authOpts = {
appToken: process.env.APP_TOKEN
}

let authenticatedRunner: ReturnType<typeof createRunner>

beforeAll(() => {
query = createQuery('w7w3-xahh')
runner = createRunner()
authenticatedRunner = createRunner(authOpts)
})

it('successfully grabs ', async () => {
const res = await runner(query)

expect(res.length).toBeGreaterThan(1)
})

it('successfully grabs with authentication ', async () => {
expect(authOpts.appToken).not.toBeUndefined()
const res = await authenticatedRunner(query)
expect(res.length).toBeGreaterThan(1)
})

it('runner fails when invalid token provided', async () => {
const misAuthenticatedRunner = createRunner({
appToken: 'au7shiadu7fhdas7s'
})

await expect(
misAuthenticatedRunner(query)
).rejects.toThrow()
})
})

0 comments on commit 10418dc

Please sign in to comment.