-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sync data with Google Drive #930
Open
SarahRemus
wants to merge
31
commits into
thamara:sync
Choose a base branch
from
SarahRemus:sync-data-with-google-drive
base: sync
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 27 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
b237802
Add menu buttons to sync with google drive
4505718
Add google-api to dependencies
75c8cbd
use example code to connect to google drive api
cf52e41
test code to upload data to drive
a018ac0
export db as JSON to google drive
09d84da
download json file from google drive
844b8e3
first draft of importing data from google drive
1b0bf2d
Refactor export, add confirmation & success window
3b5e324
confirmation window for db import
49ca41e
fix formating
8277abb
Merge branch 'thamara:main' into sync-data-with-google-drive
SarahRemus 84388a8
reload calendar after database import
ea53ce6
err handling for data export
a4ec25f
err handling for data import
9ec0781
simplify export function
2409a89
cleanup and formatting
a70d0ab
Added test for import from buffer
f283351
rename function
9edb738
Added test for get database as json
84b8624
refactor code structure
848f341
refactor code structure
373e66b
refactor code structure
e8e6d23
Add tests for import from drive
80c33d8
Fix format
f1b53eb
update package lock
da1ba39
fix requested formatting
7d3ea75
fix requested formatting
413d538
log errors to console
efea2b4
various small requested changes
2191298
remove regular entry from import fun & test case
5bc08ea
revert unrelated changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,51 @@ | ||
'use strict'; | ||
const Store = require('electron-store'); | ||
const { importDatabaseFromGoogleDrive } = require('../../js/import-export-online'); | ||
|
||
// first five entries are invalid, second five are valid | ||
const invalidEntriesContent = | ||
`[{"type": "regular", "date": "not-a-date", "data": "day-begin", "hours": "08:00"}, | ||
{"type": "waived", "date": "2020-01-01", "data": "example waiver 2", "hours": "not-an-hour"}, | ||
{"type": "regular", "date": "not-a-date", "data": "day-end", "hours": "17:00"}, | ||
{"type": "flexible", "date": "not-a-date", "values": "not-an-array"}, | ||
{"type": "not-a-type", "date": "not-a-date", "data": "day-end", "hours": "17:00"}, | ||
{"type": "flexible","date": "2020-4-1","values": ["08:00","12:00","13:00","17:00"]}, | ||
{"type": "flexible","date": "2020-4-2","values": ["07:00","11:00","14:00","18:00"]}, | ||
{"type": "waived","date": "2019-12-31","data": "New Year's eve","hours": "08:00"}, | ||
{"type": "waived","date": "2020-01-01","data": "New Year's Day","hours": "08:00"}, | ||
{"type": "waived","date": "2020-04-10","data": "Good Friday","hours": "08:00"} | ||
]`; | ||
|
||
jest.mock('../../js/google-drive', () => ({ | ||
authorize: jest.fn(), | ||
searchFile: jest.fn(), | ||
downloadFile: jest.fn().mockResolvedValue(invalidEntriesContent), | ||
})); | ||
|
||
describe('Faulty import from google drive', function() | ||
{ | ||
process.env.NODE_ENV = 'test'; | ||
const store = new Store(); | ||
const flexibleStore = new Store({ name: 'flexible-store' }); | ||
const waivedWorkdays = new Store({ name: 'waived-workdays' }); | ||
store.clear(); | ||
flexibleStore.clear(); | ||
waivedWorkdays.clear(); | ||
|
||
test('Check that invalid json is not imported', async() => | ||
{ | ||
expect(store.size).toBe(0); | ||
expect(flexibleStore.size).toBe(0); | ||
expect(waivedWorkdays.size).toBe(0); | ||
|
||
const data = await importDatabaseFromGoogleDrive(); | ||
|
||
expect(data['result']).not.toBeTruthy(); | ||
expect(data['failed']).toBe(5); | ||
expect(data['total']).toBe(10); | ||
|
||
expect(store.size).toBe(0); | ||
expect(flexibleStore.size).toBe(2); | ||
expect(waivedWorkdays.size).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* eslint-disable no-undef */ | ||
'use strict'; | ||
const Store = require('electron-store'); | ||
const { importDatabaseFromGoogleDrive } = require('../../js/import-export-online'); | ||
|
||
const notValidJSON = | ||
'[{"type": "flexible","date": "2022-11-6","values": "08:44","08:45"]}]'; | ||
|
||
jest.mock('../../js/google-drive', () => ({ | ||
authorize: jest.fn(), | ||
searchFile: jest.fn(), | ||
downloadFile: jest.fn().mockResolvedValue(notValidJSON), | ||
})); | ||
|
||
describe('Invalid import from google drive', function() | ||
{ | ||
process.env.NODE_ENV = 'test'; | ||
const store = new Store(); | ||
const flexibleStore = new Store({ name: 'flexible-store' }); | ||
const waivedWorkdays = new Store({ name: 'waived-workdays' }); | ||
store.clear(); | ||
flexibleStore.clear(); | ||
waivedWorkdays.clear(); | ||
|
||
test('Check that invalid json is not imported', async() => | ||
{ | ||
expect(store.size).toBe(0); | ||
expect(flexibleStore.size).toBe(0); | ||
expect(waivedWorkdays.size).toBe(0); | ||
|
||
const data = await importDatabaseFromGoogleDrive(); | ||
|
||
expect(data['result']).not.toBeTruthy(); | ||
expect(data['failed']).toBe(0); | ||
expect(data['total']).toBe(0); | ||
|
||
expect(store.size).toBe(0); | ||
expect(flexibleStore.size).toBe(0); | ||
expect(waivedWorkdays.size).toBe(0); | ||
}); | ||
}); |
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,45 @@ | ||
/* eslint-disable no-undef */ | ||
'use strict'; | ||
|
||
const { importDatabaseFromGoogleDrive } = require('../../js/import-export-online'); | ||
const Store = require('electron-store'); | ||
|
||
const regularEntriesJSON = | ||
`[{"type": "flexible","date": "2020-4-1","values": ["08:00","12:00","13:00","17:00"]}, | ||
{"type": "flexible","date": "2020-4-2","values": ["07:00","11:00","14:00","18:00"]}, | ||
{"type": "waived","date": "2019-12-31","data": "New Year's eve","hours": "08:00"}, | ||
{"type": "waived","date": "2020-01-01","data": "New Year's Day","hours": "08:00"}, | ||
{"type": "waived","date": "2020-04-10","data": "Good Friday","hours": "08:00"}]`; | ||
|
||
jest.mock('../../js/google-drive', () => ({ | ||
authorize: jest.fn(), | ||
searchFile: jest.fn(), | ||
downloadFile: jest.fn().mockResolvedValue(regularEntriesJSON), | ||
})); | ||
|
||
describe('Regular import from google drive', function() | ||
{ | ||
process.env.NODE_ENV = 'test'; | ||
|
||
const store = new Store(); | ||
const flexibleStore = new Store({ name: 'flexible-store' }); | ||
const waivedWorkdays = new Store({ name: 'waived-workdays' }); | ||
store.clear(); | ||
flexibleStore.clear(); | ||
waivedWorkdays.clear(); | ||
|
||
test('Check valid json is imported', async() => | ||
{ | ||
expect(store.size).toBe(0); | ||
expect(flexibleStore.size).toBe(0); | ||
expect(waivedWorkdays.size).toBe(0); | ||
|
||
const data = await importDatabaseFromGoogleDrive(); | ||
|
||
expect(data['result']).toBeTruthy(); | ||
|
||
expect(store.size).toBe(0); | ||
expect(flexibleStore.size).toBe(2); | ||
expect(waivedWorkdays.size).toBe(3); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
many of those and above are unrelated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted