-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
small refactor to error message checking code in api.ts, add ability …
…to mock UrlFetchApp methods during tests, and test new error message checking logic
- Loading branch information
Showing
6 changed files
with
262 additions
and
8 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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Matomo - free/libre analytics platform | ||
* | ||
* @link https://matomo.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
*/ | ||
|
||
import urlFetchAppMock from './urlfetchapp-mock'; | ||
|
||
const ALL_FIXTURES = { | ||
urlfetchapp: urlFetchAppMock, | ||
}; | ||
|
||
export default ALL_FIXTURES; |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Matomo - free/libre analytics platform | ||
* | ||
* @link https://matomo.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
*/ | ||
|
||
export default function urlFetchAppMock(errorToThrow: string, throwAsString: boolean = false) { | ||
const previousFetchAll = UrlFetchApp.fetchAll; | ||
let isThrown = false; | ||
|
||
return { | ||
setUp() { | ||
UrlFetchApp.fetchAll = function (...args) { | ||
if (!isThrown) { | ||
isThrown = true; | ||
|
||
if (throwAsString) { | ||
throw errorToThrow; | ||
} else { | ||
throw new Error(errorToThrow); | ||
} | ||
} else { | ||
return previousFetchAll.call(this, ...args); | ||
} | ||
}; | ||
}, | ||
tearDown() { | ||
UrlFetchApp.fetchAll = previousFetchAll; | ||
}, | ||
}; | ||
} |
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