forked from bluesky-social/atproto
-
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.
Social proof blocks (bluesky-social#2603)
* Add bidirectional blocks state * Filter out edge blocks from knownFollowers * Add tests * Destructure map Co-authored-by: devin ivy <[email protected]> * Cleanup * Consolidate known followers tests * Clean up seed, nice naming, update tests * Add mixed test * Add mergeNestedMaps, add tests * Appease linting gods * Clarify naming * minor tidy --------- Co-authored-by: devin ivy <[email protected]>
- Loading branch information
1 parent
f05539d
commit e54518f
Showing
7 changed files
with
441 additions
and
66 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
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,82 @@ | ||
import { | ||
HydrationMap, | ||
mergeMaps, | ||
mergeManyMaps, | ||
mergeNestedMaps, | ||
} from '../../src/hydration/util' | ||
|
||
const mapToObj = (map: HydrationMap<any>) => { | ||
const obj: Record<string, any> = {} | ||
for (const [key, value] of map) { | ||
obj[key] = value | ||
} | ||
return obj | ||
} | ||
|
||
describe('hydration util', () => { | ||
it(`mergeMaps: merges two maps`, () => { | ||
const compare = new HydrationMap<string>() | ||
compare.set('a', 'a') | ||
compare.set('b', 'b') | ||
|
||
const a = new HydrationMap<string>().set('a', 'a') | ||
const b = new HydrationMap<string>().set('b', 'b') | ||
const merged = mergeMaps(a, b) | ||
|
||
expect(mapToObj(merged!)).toEqual(mapToObj(compare)) | ||
}) | ||
|
||
it(`mergeManyMaps: merges three maps`, () => { | ||
const compare = new HydrationMap<string>() | ||
compare.set('a', 'a') | ||
compare.set('b', 'b') | ||
compare.set('c', 'c') | ||
|
||
const a = new HydrationMap<string>().set('a', 'a') | ||
const b = new HydrationMap<string>().set('b', 'b') | ||
const c = new HydrationMap<string>().set('c', 'c') | ||
const merged = mergeManyMaps(a, b, c) | ||
|
||
expect(mapToObj(merged!)).toEqual(mapToObj(compare)) | ||
}) | ||
|
||
it(`mergeNestedMaps: merges two nested maps`, () => { | ||
const compare = new HydrationMap<HydrationMap<string>>() | ||
const compareA = new HydrationMap<string>().set('a', 'a') | ||
const compareB = new HydrationMap<string>().set('b', 'b') | ||
compare.set('a', compareA) | ||
compare.set('b', compareB) | ||
|
||
const a = new HydrationMap<HydrationMap<string>>().set( | ||
'a', | ||
new HydrationMap<string>().set('a', 'a'), | ||
) | ||
const b = new HydrationMap<HydrationMap<string>>().set( | ||
'b', | ||
new HydrationMap<string>().set('b', 'b'), | ||
) | ||
const merged = mergeNestedMaps(a, b) | ||
|
||
expect(mapToObj(merged!)).toEqual(mapToObj(compare)) | ||
}) | ||
|
||
it(`mergeNestedMaps: merges two nested maps with common keys`, () => { | ||
const compare = new HydrationMap<HydrationMap<boolean>>() | ||
const compareA = new HydrationMap<boolean>() | ||
compareA.set('b', true) | ||
compareA.set('c', true) | ||
compare.set('a', compareA) | ||
|
||
const a = new HydrationMap<HydrationMap<boolean>>().set( | ||
'a', | ||
new HydrationMap<boolean>().set('b', true), | ||
) | ||
const b = new HydrationMap<HydrationMap<boolean>>().set( | ||
'a', | ||
new HydrationMap<boolean>().set('c', true), | ||
) | ||
const merged = mergeNestedMaps(a, b) | ||
|
||
expect(mapToObj(merged!)).toEqual(mapToObj(compare)) | ||
}) | ||
}) |
Oops, something went wrong.