-
Notifications
You must be signed in to change notification settings - Fork 114
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
🏗️🗃️ UnifiedDataLoader rewrite #1064
Merged
shankari
merged 39 commits into
e-mission:service_rewrite_2023
from
the-bay-kay:UnifiedDataLoader-rewrite
Nov 11, 2023
+367
−299
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
83a4939
Removed stale code
the-bay-kay 2963e12
Rewrote unifiedDataLoader into typscript functions
the-bay-kay 36cfff6
Improved TS, generalized getUnifiedData
the-bay-kay b7abd98
Generalized combinePromises, improved TS
the-bay-kay e6abae8
Added `types` directory, updated TS
the-bay-kay 1674d46
Added first unifiedDataLoader test
the-bay-kay 8d765d0
Added rudimentary type interfaces for server data
the-bay-kay 0bb95b2
Added types for `/diary/` services!
the-bay-kay 49e1757
Added types for `controlHelper.ts`
the-bay-kay 7dd8ffb
Added tests for combinedPromises
the-bay-kay 1907966
Updated tests, formatted test file using Prettier
the-bay-kay 46c1429
Code format changes to unifiedDataLoader.ts
the-bay-kay f0da5ea
Updated Object Types
the-bay-kay 3ddf403
Moved services to separate directory
the-bay-kay ff447d7
Merge branch 'service_rewrite_2023' of https://github.com/e-mission/e…
the-bay-kay 651e983
Ran prettier on serverData, added notes on types
the-bay-kay 772f508
Fixed PromiseResolution checks
the-bay-kay aa34ac3
Added tests for promise rejection
the-bay-kay 2e5a61e
Ran unifiedDataLoader files through Prettier
the-bay-kay 30c534c
Cleaned out `www/img/` directory
the-bay-kay 9ee44ae
Merge branch 'service_rewrite_2023' into UnifiedDataLoader-rewrite
the-bay-kay 2dc232f
Merge branch 'service_rewrite_2023' into type_interfaces
the-bay-kay 9cf629e
Updated type appearances with prettier
the-bay-kay 063f5b9
Merge branch 'type_interfaces' into UnifiedDataLoader-rewrite
the-bay-kay 8a5ce8b
updated files with prettier
the-bay-kay 0e2448c
Minor fix to index.html, changed by prettier
the-bay-kay d9285d3
Ran `prettier` on remaining files
the-bay-kay 59503e6
Update www/js/services/unifiedDataLoader.ts
the-bay-kay 9a9cd92
Removed old UnifiedDataLoader
the-bay-kay 2a04319
Merge gitHub change to local repo
the-bay-kay 000f08d
Refactored combinedPromises
the-bay-kay 71bee6f
Prettier cleanup
the-bay-kay bafdb47
Update www/js/services/unifiedDataLoader.ts
the-bay-kay 99534bf
Merge branch 'service_rewrite_2023' into UnifiedDataLoader-rewrite
shankari 808ab2e
Merge branch 'service_rewrite_2023' into UnifiedDataLoader-rewrite
the-bay-kay 25f7adf
Ran Prettier after merge
the-bay-kay fa95f97
Fixed imports
the-bay-kay c2bb442
Merge branch 'service_rewrite_2023' into UnifiedDataLoader-rewrite
the-bay-kay 7e8f07b
Merge cleanup
the-bay-kay 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
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,150 @@ | ||
import { mockLogger } from '../__mocks__/globalMocks'; | ||
import { removeDup, combinedPromises } from '../js/services/unifiedDataLoader'; | ||
import { ServerData } from '../js/types/serverData'; | ||
|
||
mockLogger(); | ||
|
||
const testOne: ServerData<any> = { | ||
data: '', | ||
metadata: { | ||
key: '', | ||
platform: '', | ||
write_ts: 1, // the only value checked by removeDup | ||
time_zone: '', | ||
write_fmt_time: '', | ||
write_local_dt: null, | ||
}, | ||
}; | ||
|
||
const testTwo = JSON.parse(JSON.stringify(testOne)); | ||
testTwo.metadata.write_ts = 2; | ||
const testThree = JSON.parse(JSON.stringify(testOne)); | ||
testThree.metadata.write_ts = 3; | ||
const testFour = JSON.parse(JSON.stringify(testOne)); | ||
testFour.metadata.write_ts = 4; | ||
|
||
describe('removeDup can', () => { | ||
it('work with an empty array', () => { | ||
expect(removeDup([])).toEqual([]); | ||
}); | ||
|
||
it('work with an array of len 1', () => { | ||
expect(removeDup([testOne])).toEqual([testOne]); | ||
}); | ||
|
||
it('work with an array of len >=1', () => { | ||
expect(removeDup([testOne, testTwo])).toEqual([testOne, testTwo]); | ||
expect(removeDup([testOne, testOne])).toEqual([testOne]); | ||
expect(removeDup([testOne, testTwo, testThree])).toEqual([testOne, testTwo, testThree]); | ||
expect(removeDup([testOne, testOne, testThree])).toEqual([testOne, testThree]); | ||
expect(removeDup([testOne, testOne, testOne])).toEqual([testOne]); | ||
}); | ||
}); | ||
|
||
// combinedPromises tests | ||
const promiseGenerator = (values: Array<ServerData<any>>) => { | ||
return Promise.resolve(values); | ||
}; | ||
const badPromiseGenerator = (input: string) => { | ||
return Promise.reject(input); | ||
}; | ||
|
||
it('throws an error on an empty input', async () => { | ||
expect(() => { | ||
combinedPromises([], removeDup); | ||
}).toThrow(); | ||
}); | ||
|
||
it('catches when all promises fails', async () => { | ||
expect(combinedPromises([badPromiseGenerator('')], removeDup)).rejects.toEqual(['']); | ||
expect( | ||
combinedPromises([badPromiseGenerator('bad'), badPromiseGenerator('promise')], removeDup), | ||
).rejects.toEqual(['bad', 'promise']); | ||
expect( | ||
combinedPromises( | ||
[badPromiseGenerator('very'), badPromiseGenerator('bad'), badPromiseGenerator('promise')], | ||
removeDup, | ||
), | ||
).rejects.toEqual(['very', 'bad', 'promise']); | ||
|
||
expect( | ||
combinedPromises([badPromiseGenerator('bad'), promiseGenerator([testOne])], removeDup), | ||
).resolves.toEqual([testOne]); | ||
expect( | ||
combinedPromises([promiseGenerator([testOne]), badPromiseGenerator('bad')], removeDup), | ||
).resolves.toEqual([testOne]); | ||
}); | ||
|
||
it('work with arrays of len 1', async () => { | ||
const promiseArrayOne = [promiseGenerator([testOne])]; | ||
const promiseArrayTwo = [promiseGenerator([testOne, testTwo])]; | ||
const testResultOne = await combinedPromises(promiseArrayOne, removeDup); | ||
const testResultTwo = await combinedPromises(promiseArrayTwo, removeDup); | ||
|
||
expect(testResultOne).toEqual([testOne]); | ||
expect(testResultTwo).toEqual([testOne, testTwo]); | ||
}); | ||
|
||
it('works with arrays of len 2', async () => { | ||
const promiseArrayOne = [promiseGenerator([testOne]), promiseGenerator([testTwo])]; | ||
const promiseArrayTwo = [promiseGenerator([testOne, testTwo]), promiseGenerator([testThree])]; | ||
const promiseArrayThree = [promiseGenerator([testOne]), promiseGenerator([testTwo, testThree])]; | ||
const promiseArrayFour = [ | ||
promiseGenerator([testOne, testTwo]), | ||
promiseGenerator([testThree, testFour]), | ||
]; | ||
const promiseArrayFive = [ | ||
promiseGenerator([testOne, testTwo]), | ||
promiseGenerator([testTwo, testThree]), | ||
]; | ||
|
||
const testResultOne = await combinedPromises(promiseArrayOne, removeDup); | ||
const testResultTwo = await combinedPromises(promiseArrayTwo, removeDup); | ||
const testResultThree = await combinedPromises(promiseArrayThree, removeDup); | ||
const testResultFour = await combinedPromises(promiseArrayFour, removeDup); | ||
const testResultFive = await combinedPromises(promiseArrayFive, removeDup); | ||
|
||
expect(testResultOne).toEqual([testOne, testTwo]); | ||
expect(testResultTwo).toEqual([testOne, testTwo, testThree]); | ||
expect(testResultThree).toEqual([testOne, testTwo, testThree]); | ||
expect(testResultFour).toEqual([testOne, testTwo, testThree, testFour]); | ||
expect(testResultFive).toEqual([testOne, testTwo, testThree]); | ||
}); | ||
|
||
it('works with arrays of len >= 2', async () => { | ||
const promiseArrayOne = [ | ||
promiseGenerator([testOne]), | ||
promiseGenerator([testTwo]), | ||
promiseGenerator([testThree]), | ||
]; | ||
const promiseArrayTwo = [ | ||
promiseGenerator([testOne]), | ||
promiseGenerator([testTwo]), | ||
promiseGenerator([testTwo]), | ||
]; | ||
const promiseArrayThree = [ | ||
promiseGenerator([testOne]), | ||
promiseGenerator([testTwo]), | ||
promiseGenerator([testThree, testFour]), | ||
]; | ||
const promiseArrayFour = [ | ||
promiseGenerator([testOne]), | ||
promiseGenerator([testTwo, testThree]), | ||
promiseGenerator([testFour]), | ||
]; | ||
|
||
const testResultOne = await combinedPromises(promiseArrayOne, removeDup); | ||
const testResultTwo = await combinedPromises(promiseArrayTwo, removeDup); | ||
const testResultThree = await combinedPromises(promiseArrayThree, removeDup); | ||
const testResultFour = await combinedPromises(promiseArrayFour, removeDup); | ||
|
||
expect(testResultOne).toEqual([testOne, testTwo, testThree]); | ||
expect(testResultTwo).toEqual([testOne, testTwo]); | ||
expect(testResultThree).toEqual([testOne, testTwo, testThree, testFour]); | ||
expect(testResultFour).toEqual([testOne, testTwo, testThree, testFour]); | ||
}); | ||
|
||
/* | ||
TO-DO: Once getRawEnteries can be tested via end-to-end testing, we will be able to | ||
test getUnifiedDataForInterval as well. | ||
*/ |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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
Oops, something went wrong.
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.
nit: I thought that prettier would ensure that we wouldn't have this extraneous whitespace.
Is this related to the fact that prettier changes the function to one line and so the indentation changes.