Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scenario: create status #35

Merged
merged 3 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions bin/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,21 @@ scenarios.reduce(async (promise, scenarioPath) => {
if (fixturesDiffs[0][0] === '-') {
if (doUpdate) {
console.log(`📼 New fixtures recorded`)
return write(fixtureName, newNormalizedFixtures)
return write(fixtureName, {
normalized: newNormalizedFixtures,
raw: newRawFixtures
})
}
console.log(`❌ "${fixtureName}" looks like a new fixture`)
return
}

if (doUpdate) {
console.log(`📼 Fixture updates recorded`)
return write(fixtureName, newNormalizedFixtures)
return write(fixtureName, {
normalized: newNormalizedFixtures,
raw: newRawFixtures
})
}

console.log(`❌ Fixtures are not up-to-date`)
Expand Down
33 changes: 33 additions & 0 deletions lib/normalize/combined-status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module.exports = normalizeCombinedStatus

const normalizeRepository = require('./repository')
const normalizeStatus = require('./status')
const setIfExists = require('../set-if-exists')
const temporaryRepository = require('../temporary-repository')

function normalizeCombinedStatus (response, fixture) {
// 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')

// zerofy sha
setIfExists(response, 'sha', '0000000000000000000000000000000000000000')

// normalize temporary repository & zerofy sha in URLs
setIfExists(response, 'url', url => {
return url
.replace(temporaryRepository.regex, '$1')
.replace(/[0-9a-f]{40}\/status$/, '0000000000000000000000000000000000000000/status')
})
setIfExists(response, 'commit_url', url => {
return url
.replace(temporaryRepository.regex, '$1')
.replace(/[0-9a-f]{40}$/, '0000000000000000000000000000000000000000')
})

response.statuses.forEach(normalizeStatus)
normalizeRepository(response.repository)

// zerofy sha in fixture and location header if present
fixture.path = fixture.path.replace(/[0-9a-f]{40}\/status$/, '0000000000000000000000000000000000000000/status')
}
6 changes: 2 additions & 4 deletions lib/normalize/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ function normalize (fixture) {

// rename temporary repositories
// e.g. tmp-scenario-bar-20170924033013835 => bar
if (temporaryRepository.regex.test(fixture.path)) {
fixture.path = fixture.path.replace(temporaryRepository.regex, '$1')
}
fixture.path = fixture.path.replace(temporaryRepository.regex, '$1')
if (fixture.headers.location && temporaryRepository.regex.test(fixture.headers.location)) {
fixture.headers.location = fixture.headers.location.replace(temporaryRepository.regex, '$1')
}
Expand Down Expand Up @@ -83,7 +81,7 @@ function normalize (fixture) {
responses.forEach(response => {
const entityName = toEntityName(response)
if (entityName) {
require(`./${entityName}`)(response)
require(`./${entityName}`)(response, fixture)
}
})

Expand Down
33 changes: 33 additions & 0 deletions lib/normalize/status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module.exports = normalizeStatus

const normalizeUser = require('./user')
const setIfExists = require('../set-if-exists')
const temporaryRepository = require('../temporary-repository')

function normalizeStatus (response, fixture) {
// set ID to 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')

// normalize temporary repository & zerofy sha
setIfExists(response, 'url', url => {
return url
.replace(temporaryRepository.regex, '$1')
.replace(/[0-9a-f]{40}$/, '0000000000000000000000000000000000000000')
})

normalizeUser(response.creator)

// zerofy sha in fixture and location header if present
if (typeof fixture !== 'object') {
return
}

fixture.path = fixture.path.replace(/[0-9a-f]{40}(\/statuses)?$/, '0000000000000000000000000000000000000000$1')
if (fixture.headers.location) {
fixture.headers.location = fixture.headers.location.replace(/[0-9a-f]{40}(\/statuses)?$/, '0000000000000000000000000000000000000000$1')
}
}
6 changes: 6 additions & 0 deletions lib/to-entity-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ function toEntityName (object) {
if ('content' in object && 'commit' in object) {
return 'file-change'
}
if (/\/statuses\/[0-9a-f]{40}$/.test(object.url)) {
return 'status'
}
if (/\/commits\/[0-9a-f]{40}\/status$/.test(object.url)) {
return 'combined-status'
}
}
Loading