Skip to content

Commit

Permalink
added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aa7401 committed Jun 8, 2018
1 parent c908841 commit 7f801f5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
]
}
23 changes: 14 additions & 9 deletions exercises/12_spa/books/__tests__/books.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
})

})
10 changes: 9 additions & 1 deletion exercises/12_spa/books/modules/books.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.