Skip to content

Commit

Permalink
Merge branch 'master' into kenny-#924
Browse files Browse the repository at this point in the history
  • Loading branch information
lautarodragan authored Dec 20, 2018
2 parents 5978421 + 98193a3 commit 3065e30
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 37 deletions.
1 change: 1 addition & 0 deletions .renovaterc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"enabled": false,
"extends": [
"config:base"
],
Expand Down
74 changes: 40 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"bitcoin-core": "2.0.0",
"bs58": "4.0.1",
"form-data": "2.3.3",
"ipfs-http-client": "28.0.1",
"ipfs-http-client": "28.1.0",
"joi": "14.3.0",
"koa": "2.6.2",
"koa-body": "4.0.4",
Expand Down Expand Up @@ -80,7 +80,7 @@
"cuid": "2.1.4",
"nyc": "poetapp/nyc#fbc2ed1",
"riteway": "4.0.1",
"semantic-release": "15.12.5",
"semantic-release": "15.13.1",
"sinon": "7.2.2",
"ts-node": "7.0.1",
"tsconfig-paths": "3.7.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Health/IPFSDirectoryHashDAO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class IPFSDirectoryHashDAO {
}

readonly start = async (): Promise<void> => {
await this.ipfsDirectoryHashInfoCollection.createIndex({ ipofsDirectoryHash: 1 }, { unique: true })
await this.ipfsDirectoryHashInfoCollection.createIndex({ ipfsDirectoryHash: 1 }, { unique: true })
await this.ipfsDirectoryHashInfoCollection.createIndex({ txId: 1, attempts: 1 })
}

Expand Down
180 changes: 180 additions & 0 deletions src/StorageReader/Exceptions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@

import { describe } from 'riteway'
import { FailureReason } from './DownloadFailure'
import {
NoMoreEntriesException,
InvalidClaim,
IPFSGenericError,
IPFSTimeoutError,
errorToIPFSError,
} from './Exceptions'

class FetchTimeoutError extends Error {
readonly type: string

constructor(type: string) {
super()
this.name = 'FetchError'
this.type = type
}
}

describe('src/StorageReader/Exceptions', async assert => {

{
const noMoreEntriesException = new NoMoreEntriesException('noMoreEntriesException')
const parseError = JSON.parse(JSON.stringify(noMoreEntriesException))
const actual = parseError.message
const expected = 'noMoreEntriesException'

assert({
given: 'a NoMoreEntriesException',
should: 'be the message property noMoreEntriesException',
actual,
expected,
})
}

{
const ipfsFileHash = 'ipfsFileHash'
const failureReason = FailureReason.IPFSGeneric
const failureTime = new Date().getTime()

const invalidClaim = new InvalidClaim(ipfsFileHash, failureReason, failureTime)
const parseError = JSON.parse(JSON.stringify(invalidClaim))

const actual = {
ipfsFileHash: parseError.ipfsFileHash,
failureReason: parseError.failureReason,
failureTime: parseError.failureTime,
message: parseError.message,
type: parseError.type,
}

const expected = {
ipfsFileHash,
failureReason,
failureTime,
message: '',
type: 'InvalidClaim',
}

assert({
given: 'a InvalidClaim',
should: 'return all properties of an InvalidClaim Error',
actual,
expected,
})
}

{
const ipfsFileHash = 'ipfsFileHash'
const failureReason = FailureReason.IPFSGeneric

const invalidClaim = new InvalidClaim(ipfsFileHash, failureReason)
const parseError = JSON.parse(JSON.stringify(invalidClaim))

const actual = typeof(parseError.failureTime)
const expected = 'number'

assert({
given: 'a failureTime undefined on InvalidClaim',
should: 'return failureTime like a number',
actual,
expected,
})
}

{
const ipfsFileHash = 'ipfsFileHash'
const underlyingError = new Error('error')
const failureTime = new Date().getTime()

const ipfsGenericError = new IPFSGenericError(ipfsFileHash, underlyingError, failureTime)
const parseError = JSON.parse(JSON.stringify(ipfsGenericError))

const actual = {
ipfsFileHash: parseError.ipfsFileHash,
underlyingError: parseError.underlyingError.message,
failureTime: parseError.failureTime,
message: parseError.message,
type: parseError.type,
}

const expected = {
ipfsFileHash,
underlyingError: underlyingError.message,
failureTime,
message: '',
type: 'IPFSGenericError',
}

assert({
given: 'a IPFSGenericError',
should: 'return all properties of an IPFSGenericError Error',
actual,
expected,
})
}

{
const ipfsFileHash = 'ipfsFileHash'
const failureTime = new Date().getTime()

const ipfsTimeoutError = new IPFSTimeoutError(ipfsFileHash, failureTime)
const parseError = JSON.parse(JSON.stringify(ipfsTimeoutError))

const actual = {
ipfsFileHash: parseError.ipfsFileHash,
failureTime: parseError.failureTime,
message: parseError.message,
type: parseError.type,
}

const expected = {
ipfsFileHash,
failureTime,
message: '',
type: 'IPFSTimeoutError',
}

assert({
given: 'a IPFSTimeoutError',
should: 'return all properties of an IPFSTimeoutError Error',
actual,
expected,
})
}

{
const ipfsFileHash = 'ipfsFileHash'
const customError = new Error()
const error = errorToIPFSError(ipfsFileHash)(customError)

const actual = JSON.parse(JSON.stringify(error)).type
const expected = 'IPFSGenericError'

assert({
given: 'a any type Error for errorToIPFSError',
should: 'return a IPFSGenericError type error',
actual,
expected,
})
}

{
const ipfsFileHash = 'ipfsFileHash'
const fetchError = new FetchTimeoutError('request-timeout')
const error = errorToIPFSError(ipfsFileHash)(fetchError)

const actual = JSON.parse(JSON.stringify(error)).type
const expected = 'IPFSTimeoutError'

assert({
given: 'a IPFSTimeoutError for errorToIPFSError',
should: 'return a IPFSTimeoutError type error',
actual,
expected,
})
}
})
1 change: 1 addition & 0 deletions tests/unit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import '../../src/Helpers/to-promise.test'
import '../../src/Interfaces.test'
import '../../src/LoadConfiguration.test'
import '../../src/Messaging/Messages.test'
import '../../src/StorageReader/Exceptions.test'
import '../../src/StorageWriter/DAOClaims.test'
import '../../src/StorageWriter/Exceptions.test'
import '../../src/StorageWriter/Router.test'

0 comments on commit 3065e30

Please sign in to comment.