-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathsheets.js
More file actions
103 lines (84 loc) · 2.94 KB
/
Copy pathsheets.js
File metadata and controls
103 lines (84 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2016 Google Inc. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE
'use strict';
const GSheets = require('../lib/sheets/gsheets').GSheets;
const Sheets = require('../lib/sheets').Sheets;
const {getMessage} = require('../lib/utils/messages');
const runOptions = require('./fixtures/run-options');
const {metricsResults, sheetsResponse, valuesToAppend} = require('./fixtures/mocks');
/* eslint-env mocha */
describe('Sheets', () => {
let sheets;
beforeEach(() => {
sheets = new Sheets(runOptions.sheets, runOptions.clientSecret);
});
describe('validateOptions', () => {
it('should throw an Error if config was not passed as parameter', () => {
expect((_ => sheets.validateOptions()))
.to.throw(getMessage('NO_GOOGLE_SHEET_OPTIONS'));
});
it('should throw an Error if config is empty', () => {
expect((_ => sheets.validateOptions({})))
.to.throw(getMessage('NO_GOOGLE_SHEET_OPTIONS'));
});
it('should throw an Error if type is wrong', () => {
expect((_ => sheets.validateOptions( {type: 'WRONG_TYPE', options: runOptions.sheets.options} )))
.to.throw(getMessage('NO_SHEET_TYPE', 'WRONG_TYPE'));
});
it('should throw an Error if one of require options are missed', () => {
expect((_ => sheets.validateOptions({
type: runOptions.sheets.type,
options: {
tableName: 'data'
},
clientSecret: {}
}))).to.throw(getMessage('NO_GOOGLE_SHEET_OPTIONS'));
expect((_ => sheets.validateOptions({
type: runOptions.sheets.type,
options: {
spreadsheetId: '123456'
},
clientSecret: {}
}))).to.throw(getMessage('NO_GOOGLE_SHEET_OPTIONS'));
expect((_ => sheets.validateOptions({
type: runOptions.sheets.type,
options: {
spreadsheetId: '123456',
tableName: 'data',
}
}))).to.throw(getMessage('NO_GOOGLE_SHEET_OPTIONS'));
});
});
describe('appendResults', () => {
beforeEach(() => {
sinon.stub(sheets, 'appendResultsToGSheets', () => {});
});
it('should call "appendResultsToGSheets" method', () => {
sheets.appendResults({});
expect(sheets.appendResultsToGSheets).to.have.been.calledWith({});
});
afterEach(() => {
sheets.appendResultsToGSheets.restore();
});
});
describe('appendResultsToGSheets', () => {
});
describe('gSheets', () => {
let oauthStub;
let spy;
beforeEach(() => {
oauthStub = sinon.stub(sheets, 'getOauth', () => {
return 'oauth';
});
sinon.stub(GSheets.prototype, 'sendResultsToGoogle', () => sheetsResponse);
spy = sinon.stub(GSheets.prototype, 'getRange', () => valuesToAppend);
});
afterEach(() => {
oauthStub.restore();
});
it('should at least consider running', async() => {
sheets.appendResults(metricsResults);
sinon.assert.calledOnce(spy);
});
});
});