Skip to content

Commit

Permalink
fix(normalization): set IDs to 1
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Sep 18, 2017
1 parent 0a419d3 commit 0f8556e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 17 deletions.
4 changes: 1 addition & 3 deletions lib/normalize/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ function normalize (fixture) {
delete fixture.rawHeaders

// set all dates to Universe 2017 Keynote time
setIfExists(fixture.response, 'created_at', '2017-10-10T16:00:00Z')
setIfExists(fixture.response, 'updated_at', '2017-10-10T16:00:00Z')
setIfExists(fixture.headers, 'date', 'Tue, 10 Oct 2017 16:00:00 GMT')
setIfExists(fixture.headers, 'last-modified', 'Tue, 10 Oct 2017 16:00:00 GMT')
setIfExists(fixture.headers, 'x-ratelimit-reset', '1507651200000')
Expand Down Expand Up @@ -54,7 +52,7 @@ function normalize (fixture) {

const entityName = toEntityName(fixture.response)
if (entityName) {
require(`./${entityName}`)(fixture)
require(`./${entityName}`)(fixture.response)
}

// update content length
Expand Down
12 changes: 10 additions & 2 deletions lib/normalize/organization.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ module.exports = normalizeOrganization

const setIfExists = require('../set-if-exists')

function normalizeOrganization (fixture) {
function normalizeOrganization (response) {
// set all IDs to 1
setIfExists(response, 'avatar_url', value => value.replace(response.id, 1))
setIfExists(response, 'id', 1)

// set all dates to Universe 2017 Keynote time
setIfExists(response, 'created_at', '2017-10-10T16:00:00Z')
setIfExists(response, 'updated_at', '2017-10-10T16:00:00Z')

// set all counts to 42
setIfExists(fixture.response, 'public_repos', 42)
setIfExists(response, 'public_repos', 42)
}
36 changes: 25 additions & 11 deletions lib/normalize/repository.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
module.exports = normalizeRepository

const normalizeOrganization = require('./organization')
const normalizeUser = require('./user')
const setIfExists = require('../set-if-exists')

function normalizeRepository (fixture) {
function normalizeRepository (response) {
// set all IDs to 1
setIfExists(response, 'id', 1)

// set all dates to Universe 2017 Keynote time
setIfExists(fixture.response, 'pushed_at', '2017-10-10T16:00:00Z')
setIfExists(response, 'created_at', '2017-10-10T16:00:00Z')
setIfExists(response, 'updated_at', '2017-10-10T16:00:00Z')
setIfExists(response, 'pushed_at', '2017-10-10T16:00:00Z')

// set all counts to 42
setIfExists(fixture.response, 'forks_count', 42)
setIfExists(fixture.response, 'forks', 42)
setIfExists(fixture.response, 'network_count', 42)
setIfExists(fixture.response, 'open_issues_count', 42)
setIfExists(fixture.response, 'open_issues', 42)
setIfExists(fixture.response, 'stargazers_count', 42)
setIfExists(fixture.response, 'subscribers_count', 42)
setIfExists(fixture.response, 'watchers_count', 42)
setIfExists(fixture.response, 'watchers', 42)
setIfExists(response, 'forks_count', 42)
setIfExists(response, 'forks', 42)
setIfExists(response, 'network_count', 42)
setIfExists(response, 'open_issues_count', 42)
setIfExists(response, 'open_issues', 42)
setIfExists(response, 'stargazers_count', 42)
setIfExists(response, 'subscribers_count', 42)
setIfExists(response, 'watchers_count', 42)
setIfExists(response, 'watchers', 42)

if (response.organization) {
normalizeOrganization(response.owner)
normalizeOrganization(response.organization)
} else {
normalizeUser(response.owner)
}
}
9 changes: 9 additions & 0 deletions lib/normalize/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = normalizeUser

const setIfExists = require('../set-if-exists')

function normalizeUser (response) {
// set all IDs to 1
setIfExists(response, 'avatar_url', value => value.replace(response.id, 1))
setIfExists(response, 'id', 1)
}
2 changes: 1 addition & 1 deletion lib/set-if-exists.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ module.exports = setIfExists

function setIfExists (object, key, value) {
if (key in object) {
object[key] = value
object[key] = typeof value === 'function' ? value(object[key]) : value
}
}

0 comments on commit 0f8556e

Please sign in to comment.