fix(nock): Fixed failing tests mocked with nock

This commit is contained in:
Chris Troutner
2019-10-28 10:49:49 -07:00
parent 888a7a6b75
commit c3cf9ad494
10 changed files with 350 additions and 720 deletions
+6 -5
View File
@@ -385,8 +385,9 @@ describe("#Block", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
console.log(`process.env.RPC_BASEURL: ${process.env.RPC_BASEURL}`)
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(500, {
error: {
code: -1,
@@ -410,7 +411,7 @@ describe("#Block", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockBlockHash })
}
@@ -501,7 +502,7 @@ describe("#Block", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(500, {
error: {
code: -1,
@@ -546,7 +547,7 @@ describe("#Block", () => {
// Mock the Insight URL for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockBlockHash })
nock(`${process.env.BITCOINCOM_BASEURL}`)
@@ -589,7 +590,7 @@ describe("#Block", () => {
// Mock the Insight URL for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.times(2)
.reply(200, { result: mockData.mockBlockHash })
+20 -20
View File
@@ -119,7 +119,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockBlockHash })
}
@@ -161,7 +161,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockBlockchainInfo })
}
@@ -213,7 +213,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: 126769 })
}
@@ -264,7 +264,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, {
result:
"000000202ed2723e7590e2b937f6821a99d6764cb8799bf30f8e300000000000000000001d311c02df9a1e3f57b8dbdcf97ec8dbc3109a26779724c63e560b29ad9ea501e2af955d286403183049e39c"
@@ -288,7 +288,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockBlockHeader })
}
@@ -404,7 +404,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockBlockHeaderConcise })
}
@@ -431,7 +431,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockBlockHeader })
}
@@ -468,7 +468,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.times(2)
.reply(200, { result: mockData.mockBlockHeaderConcise })
}
@@ -511,7 +511,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockChainTips })
}
@@ -552,7 +552,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: 4049809.205246544 })
}
@@ -592,7 +592,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockMempoolInfo })
}
@@ -638,7 +638,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockRawMempool })
}
@@ -690,7 +690,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: { error: "Transaction not in mempool" } })
}
@@ -836,7 +836,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockTxOut })
}
@@ -902,7 +902,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockTxOutProof })
}
@@ -963,7 +963,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockTxOutProof })
}
@@ -982,7 +982,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.times(2)
.reply(200, { result: mockData.mockTxOutProof })
}
@@ -1042,7 +1042,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: [expected] })
}
@@ -1109,7 +1109,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: [expected] })
}
@@ -1132,7 +1132,7 @@ describe("#BlockchainRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.times(2)
.reply(200, { result: [expected] })
}
+1 -1
View File
@@ -115,7 +115,7 @@ describe("#ControlRouter", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockGetNetworkInfo })
}
+2 -2
View File
@@ -114,7 +114,7 @@ describe("#Mining", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockMiningInfo })
}
@@ -163,7 +163,7 @@ describe("#Mining", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: 517604755.6648782 })
}
+16 -16
View File
@@ -134,7 +134,7 @@ describe("#Raw-Transactions", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockDecodeRawTransaction })
}
@@ -211,7 +211,7 @@ describe("#Raw-Transactions", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockDecodeRawTransaction })
}
@@ -240,7 +240,7 @@ describe("#Raw-Transactions", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.times(2)
.reply(200, { result: mockData.mockDecodeRawTransaction })
}
@@ -309,7 +309,7 @@ describe("#Raw-Transactions", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockDecodeScript })
}
@@ -375,7 +375,7 @@ describe("#Raw-Transactions", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockDecodeScript })
}
@@ -394,7 +394,7 @@ describe("#Raw-Transactions", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.times(2)
.reply(200, { result: mockData.mockDecodeScript })
}
@@ -453,7 +453,7 @@ describe("#Raw-Transactions", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(500, {
error: { message: "parameter 1 must be of length 64 (not 6)" }
})
@@ -473,7 +473,7 @@ describe("#Raw-Transactions", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockRawTransactionConcise })
}
@@ -492,7 +492,7 @@ describe("#Raw-Transactions", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockRawTransactionVerbose })
}
@@ -541,7 +541,7 @@ describe("#Raw-Transactions", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(500, {
error: { message: "parameter 1 must be of length 64 (not 6)" }
})
@@ -561,7 +561,7 @@ describe("#Raw-Transactions", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockRawTransactionConcise })
}
@@ -578,7 +578,7 @@ describe("#Raw-Transactions", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockRawTransactionVerbose })
}
@@ -647,7 +647,7 @@ describe("#Raw-Transactions", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(500, {
error: { message: "TX decode failed" }
})
@@ -671,7 +671,7 @@ describe("#Raw-Transactions", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, {
result:
"aef8848396e67532b42008b9d75b5a5a3459a6717740f31f0553b74102b4b118"
@@ -759,7 +759,7 @@ describe("#Raw-Transactions", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(500, {
error: { message: "TX decode failed" }
})
@@ -781,7 +781,7 @@ describe("#Raw-Transactions", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, {
result:
"aef8848396e67532b42008b9d75b5a5a3459a6717740f31f0553b74102b4b118"
+35 -33
View File
@@ -717,7 +717,7 @@ describe("#SLP", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.SLPDB_URL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockConvert })
}
@@ -832,45 +832,47 @@ describe("#SLP", () => {
assert.include(result.error, "Array too large")
})
it("should validate array with single element", async () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
sandbox
.stub(slpRoute.testableComponents, "isValidSlpTxid")
.resolves(true)
}
if (process.env.TEST === "integration") {
it("should validate array with single element", async () => {
// Mock the RPC call for unit tests.
// if (process.env.TEST === "unit") {
// sandbox
// .stub(slpRoute.testableComponents, "isValidSlpTxid")
// .resolves(true)
// }
req.body.txids = [
"77872738b6bddee6c0cbdb9509603de20b15d4f6b26602f629417aec2f5d5e8d"
]
req.body.txids = [
"77872738b6bddee6c0cbdb9509603de20b15d4f6b26602f629417aec2f5d5e8d"
]
const result = await validateBulk(req, res)
// console.log(`result: ${util.inspect(result)}`)
const result = await validateBulk(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.isArray(result)
assert.hasAllKeys(result[0], ["txid", "valid"])
})
assert.isArray(result)
assert.hasAllKeys(result[0], ["txid", "valid"])
})
it("should validate array with two elements", async () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
sandbox
.stub(slpRoute.testableComponents, "isValidSlpTxid")
.resolves(true)
}
it("should validate array with two elements", async () => {
// Mock the RPC call for unit tests.
// if (process.env.TEST === "unit") {
// sandbox
// .stub(slpRoute.testableComponents, "isValidSlpTxid")
// .resolves(true)
// }
req.body.txids = [
"77872738b6bddee6c0cbdb9509603de20b15d4f6b26602f629417aec2f5d5e8d",
"77872738b6bddee6c0cbdb9509603de20b15d4f6b26602f629417aec2f5d5e8d"
]
req.body.txids = [
"77872738b6bddee6c0cbdb9509603de20b15d4f6b26602f629417aec2f5d5e8d",
"77872738b6bddee6c0cbdb9509603de20b15d4f6b26602f629417aec2f5d5e8d"
]
const result = await validateBulk(req, res)
// console.log(`result: ${util.inspect(result)}`)
const result = await validateBulk(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.isArray(result)
assert.hasAllKeys(result[0], ["txid", "valid"])
assert.equal(result.length, 2)
})
assert.isArray(result)
assert.hasAllKeys(result[0], ["txid", "valid"])
assert.equal(result.length, 2)
})
}
})
describe("tokenStatsSingle()", () => {
+3 -3
View File
@@ -135,7 +135,7 @@ describe("#Util", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockAddress })
}
@@ -255,7 +255,7 @@ describe("#Util", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.reply(200, { result: mockData.mockAddress })
}
@@ -281,7 +281,7 @@ describe("#Util", () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.RPC_BASEURL}`)
.post(``)
.post(uri => uri.includes("/"))
.times(2)
.reply(200, { result: mockData.mockAddress })
}