Skip to content

Instantly share code, notes, and snippets.

@lvreynoso
Last active May 20, 2019 19:28
Show Gist options
  • Save lvreynoso/f662f3ef2b1678bb074772d2bf8cc3b6 to your computer and use it in GitHub Desktop.
Save lvreynoso/f662f3ef2b1678bb074772d2bf8cc3b6 to your computer and use it in GitHub Desktop.
app.get('/charities/test', async (req, res) => {
// our test object that holds the test queries we are going to send
let test = {
result: {},
collection: {},
organization: {}
};
// build a basic query string to test if we can access the class methods correctly
test.result.query = modules.charityNavigator.test()
// test the collection() function
// should build the proper URL string for the query we want
// this is supposed to return a list of charities that are relevant
// to our query, structured according to the number of results per page
// and page number that we pass to it
try {
test.collection.query = modules.charityNavigator.collection('10', '1', 'fire')
const collection = await modules.axios.get(test.collection.query)
test.collection.response = collection;
// If this doesn't work, log the error and break out of the function
} catch (error) {
console.log(error);
test.collection.response = String(error.response.status + ' ' + error.response.statusText)
return res.render('charities-test', {
test: test
})
}
// test the organization() function
// this should build the proper URL string to get information on a single
// charity, based on the EIN we pass to it.
try {
test.organization.query = modules.charityNavigator.organization('411867244');
const organization = modules.axios.get(test.organization.query) // test ein
test.organization.response = organization;
// tests done, render the page
res.render('charities-test', {
test: test
})
// If this doesn't work, log the error and break out of the function
} catch (error) {
console.log(error);
test.organization.response = String(error.response.status + ' ' + error.response.statusText)
return res.render('charities-test', {
test: test
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment