Created
March 23, 2021 20:29
-
-
Save mpaccione/8340b0fb7f8eea43fa837ec10e013562 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const fetch = require("node-fetch"); | |
let obj; | |
const file1 = "requestlog-charges.json"; | |
const file2 = "requestlog-customer-charges.json"; | |
// Read the local json reqeust responses store to variable | |
(function () { | |
const customerPointers = {}; | |
fs.readFile(file2, "utf8", function (err, data) { | |
// console.log({ err }); | |
if (err) throw err; | |
obj = JSON.parse(data); | |
// console.log({ obj }); | |
obj.forEach(async (ajaxObj, index) => { | |
const { url, headers, body, method } = ajaxObj.request; | |
const { code } = ajaxObj.response; | |
const expectedBody = JSON.parse(ajaxObj.response.body); | |
console.log(`https://api.stripe.com${url}`); | |
const ajaxVars = | |
method === "POST" | |
? { | |
method, | |
headers, | |
body, | |
} | |
: { | |
method, | |
headers, | |
}; | |
const response = await fetch(`https://api.stripe.com${url}`, ajaxVars); | |
const res = await response.json(); | |
// Match Status Codes - Testing | |
if (response.status !== code) { | |
console.log(`PROBLEM INDEX: ${index}`); | |
} else { | |
console.log(`PASS INDEX: ${index}`); | |
// Get Customer Id via substring | |
customerPointers[expectedBody.id] = res.id; | |
console.log(customerPointers); | |
} | |
}); | |
}); | |
})(); | |
// Make AJAX call | |
console.log("TEST"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment