-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic tests related to sheets-connection main methods and range…
… logic tests, little fixes in README and sheets-connection.ts
- Loading branch information
Showing
7 changed files
with
242 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ node_modules | |
package-lock.json | ||
build | ||
.idea | ||
coverage | ||
coverage | ||
.env |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,7 @@ | |
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
"testPathIgnorePatterns" : [ | ||
"./build", | ||
] | ||
}; |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,225 @@ | ||
import { test, expect } from '@jest/globals'; | ||
import {describe, expect, test} from '@jest/globals'; | ||
import {GoogleSheetsAuth} from "../../auth/google-sheets-auth"; | ||
import {SheetsConnection} from "../sheets-connection"; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
// Auth setup | ||
const key = process.env.GOOGLE_KEY!.toString().split('\\n').map(i => i + "\n").join(""); | ||
|
||
const googleAuthWrapper = new GoogleSheetsAuth({ | ||
email: process.env.GOOGLE_EMAIL!, | ||
key: key | ||
}).login(); | ||
|
||
describe('SheetsConnection main methods', () => { | ||
|
||
const sheetsConnection = new SheetsConnection({ | ||
spreadsheetId: process.env.SHEET_ID!, | ||
auth: googleAuthWrapper, | ||
sheet: "Sheet1", | ||
range: "A1:B" | ||
}); | ||
|
||
test('Expect get method to work', async () => { | ||
expect(await sheetsConnection.get()).toBeTruthy(); | ||
}); | ||
|
||
test('Expect append method to work', async () => { | ||
expect(await sheetsConnection.append([[ | ||
"test1", | ||
"test2" | ||
]])).toBeTruthy(); | ||
}); | ||
|
||
test('Expect update method to work', async () => { | ||
expect(await sheetsConnection.update([[ | ||
"test3", | ||
"test4" | ||
]])).toBeTruthy(); | ||
}); | ||
|
||
test('Expect clear method to work', async () => { | ||
expect(await sheetsConnection.clear()).toBeTruthy(); | ||
}); | ||
|
||
}); | ||
|
||
describe('Range logic checks', () => { | ||
|
||
test('Expect range to be this.sheetRange when sheet and range in constructor', async () => { | ||
const range = "A1:B2"; | ||
const sheet = "Sheet1"; | ||
|
||
const sheetsConnection = new SheetsConnection({ | ||
spreadsheetId: process.env.SHEET_ID!, | ||
auth: googleAuthWrapper, | ||
sheet, | ||
range | ||
}); | ||
|
||
const response = await sheetsConnection.get(); | ||
|
||
expect(response.data.range).toBe(sheet + "!" + range); | ||
}); | ||
|
||
test('Expect range to be `${cfg.sheet}!${cfg.range}` when sheet and range in method', async () => { | ||
const range = "A1:B2"; | ||
const sheet = "Sheet1"; | ||
|
||
const sheetsConnection = new SheetsConnection({ | ||
spreadsheetId: process.env.SHEET_ID!, | ||
auth: googleAuthWrapper, | ||
}); | ||
|
||
const response = await sheetsConnection.get({ | ||
sheet, | ||
range | ||
}); | ||
|
||
expect(response.data.range).toBe(sheet + "!" + range); | ||
}); | ||
|
||
test('Expect range to be `${cfg.sheet}!${cfg.range}` when sheet and range in method and constructor', async () => { | ||
const range = "A1:B2"; | ||
const sheet = "Sheet1"; | ||
|
||
const sheetsConnection = new SheetsConnection({ | ||
spreadsheetId: process.env.SHEET_ID!, | ||
auth: googleAuthWrapper, | ||
sheet: "Sheet2", | ||
range: "C1:D2" | ||
}); | ||
|
||
const response = await sheetsConnection.get({ | ||
sheet, | ||
range | ||
}); | ||
|
||
expect(response.data.range).toBe(sheet + "!" + range); | ||
}); | ||
|
||
test('Expect range to be `${this.sheet}!${cfg.range}` when sheet and range in constructor and range in method', async () => { | ||
const range = "A1:B2"; | ||
const sheet = "Sheet1"; | ||
|
||
const sheetsConnection = new SheetsConnection({ | ||
spreadsheetId: process.env.SHEET_ID!, | ||
auth: googleAuthWrapper, | ||
sheet, | ||
range: "C1:D2" | ||
}); | ||
|
||
const response = await sheetsConnection.get({ | ||
range | ||
}); | ||
|
||
expect(response.data.range).toBe(sheet + "!" + range); | ||
}); | ||
|
||
test('Expect range to be `${this.sheet}!${cfg.range}` when sheet in constructor and range in method', async () => { | ||
const range = "A1:B2"; | ||
const sheet = "Sheet1"; | ||
|
||
const sheetsConnection = new SheetsConnection({ | ||
spreadsheetId: process.env.SHEET_ID!, | ||
auth: googleAuthWrapper, | ||
sheet, | ||
}); | ||
|
||
const response = await sheetsConnection.get({ | ||
range | ||
}); | ||
|
||
expect(response.data.range).toBe(sheet + "!" + range); | ||
}); | ||
|
||
test('Expect error when sheet only in constructor', async () => { | ||
const sheet = "Sheet1"; | ||
|
||
const sheetsConnection = new SheetsConnection({ | ||
spreadsheetId: process.env.SHEET_ID!, | ||
auth: googleAuthWrapper, | ||
sheet, | ||
}); | ||
|
||
await expect(sheetsConnection.get()).rejects.toThrowError("Specify range or sheet in method or in constructor"); | ||
}); | ||
|
||
test('Expect error when range only in constructor', async () => { | ||
const range = "A1:B2"; | ||
|
||
const sheetsConnection = new SheetsConnection({ | ||
spreadsheetId: process.env.SHEET_ID!, | ||
auth: googleAuthWrapper, | ||
range, | ||
}); | ||
|
||
await expect(sheetsConnection.get()).rejects.toThrowError("Specify range or sheet in method or in constructor"); | ||
}); | ||
|
||
test('Expect error when sheet only in method', async () => { | ||
const sheet = "Sheet1"; | ||
|
||
const sheetsConnection = new SheetsConnection({ | ||
spreadsheetId: process.env.SHEET_ID!, | ||
auth: googleAuthWrapper, | ||
}); | ||
|
||
await expect(sheetsConnection.get({sheet})).rejects.toThrowError("Specify range or sheet in method or in constructor"); | ||
}); | ||
|
||
test('Expect error when range only in method', async () => { | ||
const range = "A1:B2"; | ||
|
||
const sheetsConnection = new SheetsConnection({ | ||
spreadsheetId: process.env.SHEET_ID!, | ||
auth: googleAuthWrapper, | ||
}); | ||
|
||
await expect(sheetsConnection.get({range})).rejects.toThrowError("Specify range or sheet in method or in constructor"); | ||
}); | ||
|
||
test('Expect error when sheet and range in constructor and sheet in method', async () => { | ||
const sheetsConnection = new SheetsConnection({ | ||
spreadsheetId: process.env.SHEET_ID!, | ||
auth: googleAuthWrapper, | ||
sheet: "Sheet1", | ||
range: "A1:B2" | ||
}); | ||
|
||
await expect(sheetsConnection.get({sheet: "Sheet2"})).rejects.toThrowError("Specify range or sheet in method or in constructor"); | ||
}); | ||
|
||
test('Expect error when range in constructor and sheet in method', async () => { | ||
const sheetsConnection = new SheetsConnection({ | ||
spreadsheetId: process.env.SHEET_ID!, | ||
auth: googleAuthWrapper, | ||
range: "A1:B2" | ||
}); | ||
|
||
await expect(sheetsConnection.get({sheet: "Sheet2"})).rejects.toThrowError("Specify range or sheet in method or in constructor"); | ||
}); | ||
|
||
test('Expect error when range in constructor and range in method', async () => { | ||
const sheetsConnection = new SheetsConnection({ | ||
spreadsheetId: process.env.SHEET_ID!, | ||
auth: googleAuthWrapper, | ||
range: "A1:B2" | ||
}); | ||
|
||
await expect(sheetsConnection.get({range: "C1:D2"})).rejects.toThrowError("Specify range or sheet in method or in constructor"); | ||
}); | ||
|
||
test('Expect error when sheet in constructor and sheet in method', async () => { | ||
const sheetsConnection = new SheetsConnection({ | ||
spreadsheetId: process.env.SHEET_ID!, | ||
auth: googleAuthWrapper, | ||
sheet: "Sheet1" | ||
}); | ||
|
||
await expect(sheetsConnection.get({sheet: "Sheet2"})).rejects.toThrowError("Specify range or sheet in method or in constructor"); | ||
}); | ||
|
||
test('adds 1 + 2 to equal 3', () => { | ||
expect(1+2).toBe(3); | ||
}); |
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