Skip to content

Commit

Permalink
release v1.0.24
Browse files Browse the repository at this point in the history
- add shield to getSpreadsheetDataUsingFetch method
- add some case and replace some variable names on test case
  • Loading branch information
fureweb-com committed Dec 1, 2020
1 parent 4da2731 commit 7a8f831
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "public-google-sheets-parser",
"version": "1.0.23",
"version": "1.0.24",
"description": "Get JSONArray from public google sheets with using only spreadsheetId",
"scripts": {
"build:dist": "npx babel ./src/index.js --out-file ./dist/index.js",
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class PublicGoogleSheetsParser {
}

getSpreadsheetDataUsingFetch () {
if (!this.id) return null

// Read data from the first sheet of the target document.
// It cannot be used unless everyone has been given read permission.
// It must be a spreadsheet document with a header, as in the example document below.
Expand Down
26 changes: 16 additions & 10 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
const test = require('tape')

const PublicGoogleSheetsParser = require('../src/index.js')
const spreadsheetId = '10WDbAPAY7Xl5DT36VuMheTPTTpqx9x0C5sDCnh4BGps'
const parser = new PublicGoogleSheetsParser(spreadsheetId)
const parser = new PublicGoogleSheetsParser()

test('getSpreadsheetDataUsingFetch method should returns expected string', async (t) => {
t.plan(1)
test('getSpreadsheetDataUsingFetch method should return expected result', async (t) => {
t.plan(2)

const resultWithoutSpreadsheetId = await parser.getSpreadsheetDataUsingFetch()
t.equal(resultWithoutSpreadsheetId, null)

const result = await parser.getSpreadsheetDataUsingFetch()
const spreadsheetId = '10WDbAPAY7Xl5DT36VuMheTPTTpqx9x0C5sDCnh4BGps'
parser.id = spreadsheetId

const resultWithSpreadsheetId = await parser.getSpreadsheetDataUsingFetch()
const expected = '/*O_o*/\ngoogle.visualization.Query.setResponse({"version":"0.6","reqId":"0","status":"ok","sig":"779687672","table":{"cols":[{"id":"A","label":"a","type":"number","pattern":"General"},{"id":"B","label":"b","type":"number","pattern":"General"},{"id":"C","label":"c","type":"number","pattern":"General"}],"rows":[{"c":[{"v":1.0,"f":"1"},{"v":2.0,"f":"2"},{"v":3.0,"f":"3"}]},{"c":[{"v":4.0,"f":"4"},{"v":5.0,"f":"5"},{"v":6.0,"f":"6"}]},{"c":[{"v":7.0,"f":"7"},{"v":8.0,"f":"8"},{"v":9.0,"f":"9"}]}],"parsedNumHeaders":1}});'
t.equal(result, expected)
t.equal(resultWithSpreadsheetId, expected)

t.end()
})
Expand Down Expand Up @@ -47,12 +52,13 @@ test('parse method should return array even spreadsheetId is invalid', async (t)
t.plan(2)

const invalidSpreadsheetId = 'id_that_does_not_exist_anywhere'
const shouldEmptyArray = await parser.parse(invalidSpreadsheetId)
t.deepEqual(shouldEmptyArray, [])
const resultWithInvalidSpreadsheetId = await parser.parse(invalidSpreadsheetId)
t.deepEqual(resultWithInvalidSpreadsheetId, [])

const result = await parser.parse(spreadsheetId)
const validSpreadsheetId = '10WDbAPAY7Xl5DT36VuMheTPTTpqx9x0C5sDCnh4BGps'
const resultWithValidSpreadsheetId = await parser.parse(validSpreadsheetId)
const expected = [{ a: 1, b: 2, c: 3 }, { a: 4, b: 5, c: 6 }, { a: 7, b: 8, c: 9 }]
t.deepEqual(result, expected)
t.deepEqual(resultWithValidSpreadsheetId, expected)

t.end()
})

0 comments on commit 7a8f831

Please sign in to comment.