Skip to content
Permalink
Browse files
added more tests
  • Loading branch information
aa7401 committed Jun 8, 2018
1 parent c908841 commit 7f801f53203cd2a5b351ab33cdc465df544bca49
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
@@ -0,0 +1,14 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest Tests",
"program": "${workspaceFolder}/exercises/12_spa/books/node_modules/.bin/jest",
"args": [
"-i"
]
}
]
}
@@ -14,12 +14,6 @@ let goodData

describe('searchGoogle', () => {

beforeAll( () => {
const path = './modules/__mocks__/__mockData__/'
goodData = fs.readFileSync(`${path}java.json`, 'utf8')
expect(typeof goodData).toBe('string')
})

test('make a simple API call', async() => {
const search = 'java'
const data = await books.searchGoogle(search)
@@ -30,18 +24,29 @@ describe('searchGoogle', () => {

describe('extractFields', () => {

test('extract title fields', () => {
beforeAll( () => {
const path = './modules/__mocks__/__mockData__/'
goodData = fs.readFileSync(`${path}java.json`, 'utf8')
expect(typeof goodData).toBe('string')
})

test('extracted data is in an array', () => {
const bookData = books.extractFields(goodData)
//console.log(bookData)
expect(Array.isArray(bookData)).toBeTruthy()
expect(bookData.length).toBe(2)
})

test('extract title fields', () => {
const bookData = books.extractFields(goodData)
console.log(bookData)
expect(bookData[0].title).toBe('Java Book One')
expect(bookData[1].title).toBe('Java Book Two')
})

test('extract ISBN13 data', () => {

const bookData = books.extractFields(goodData)
expect(bookData[0].isbn).toBe(9780201616460)
expect(bookData[1].isbn).toBe(9789793780146)
})

})
@@ -39,8 +39,16 @@ module.exports.extractFields = jsonStr => {
const json = JSON.parse(jsonStr)
if(!Array.isArray(json.items)) throw new Error('no book data found')
for(const n of json.items) {
let item = {}
console.log(n)
bookArray.push({title: n.volumeInfo.title})
item.title = n.volumeInfo.title
for(const m in n.industryIdentifiers) {
//console.log(m)
if(m.type === 'ISBN_13') {
// xxx
}
}
bookArray.push(item)
}
return bookArray
}

0 comments on commit 7f801f5

Please sign in to comment.