-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
80 changed files
with
2,982 additions
and
263 deletions.
There are no files selected for viewing
Binary file renamed
BIN
+334 KB
...ative-npm-7.8.0-c618815190-800233c950.zip → ...ative-npm-7.8.2-b551bc6447-f3b3ea1166.zip
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
26 changes: 26 additions & 0 deletions
26
apps/contact-service/src/__tests__/utils/mockedFirebaseMessagingService.ts
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,26 @@ | ||
import {Effect, Layer} from 'effect' | ||
import { | ||
type BatchResponse, | ||
type MulticastMessage, | ||
} from 'firebase-admin/messaging' | ||
import {FirebaseMessagingService} from '../../utils/notifications/FirebaseMessagingService' | ||
|
||
export const sendMessageMock = jest.fn( | ||
async ({tokens}: MulticastMessage): Promise<BatchResponse> => ({ | ||
responses: tokens.map(() => ({ | ||
success: true as const, | ||
})), | ||
successCount: tokens.length, | ||
failureCount: 0, | ||
}) | ||
) | ||
|
||
export const sendToTopicMock = jest.fn() | ||
|
||
export const mockedFirebaseMessagingServiceLayer = Layer.effect( | ||
FirebaseMessagingService, | ||
Effect.succeed({ | ||
sendEachForMulticast: sendMessageMock, | ||
sendToTopic: sendToTopicMock, | ||
}) | ||
) |
111 changes: 111 additions & 0 deletions
111
apps/contact-service/src/__tests__/utils/routes/contacts/fetchCommonConnections.test.ts
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,111 @@ | ||
import {HttpClientRequest} from '@effect/platform' | ||
import {Array, Effect, Order, pipe} from 'effect' | ||
import {NodeTestingApp} from '../../NodeTestingApp' | ||
import {runPromiseInMockedEnvironment} from '../../runPromiseInMockedEnvironment' | ||
import { | ||
createAndImportUsersFromNetwork, | ||
type DummyUser, | ||
generateKeysAndHasheForNumber, | ||
} from './utils' | ||
|
||
let networkOne: [DummyUser, ...DummyUser[]] | ||
let networkTwo: [DummyUser, ...DummyUser[]] | ||
|
||
beforeAll(async () => { | ||
await runPromiseInMockedEnvironment( | ||
Effect.gen(function* (_) { | ||
networkOne = yield* _( | ||
Effect.all([ | ||
generateKeysAndHasheForNumber('+420733333001'), | ||
generateKeysAndHasheForNumber('+420733333002'), | ||
generateKeysAndHasheForNumber('+420733333003'), | ||
generateKeysAndHasheForNumber('+420733333004'), | ||
generateKeysAndHasheForNumber('+420733333005'), | ||
]) | ||
) | ||
|
||
yield* _( | ||
Effect.forEach(networkOne, (oneUser) => | ||
createAndImportUsersFromNetwork(oneUser, networkOne) | ||
) | ||
) | ||
|
||
networkTwo = yield* _( | ||
Effect.all([ | ||
generateKeysAndHasheForNumber('+420733333101'), | ||
generateKeysAndHasheForNumber('+420733333102'), | ||
generateKeysAndHasheForNumber('+420733333106'), | ||
generateKeysAndHasheForNumber('+420733333107'), | ||
generateKeysAndHasheForNumber('+420733333108'), | ||
]) | ||
) | ||
|
||
yield* _( | ||
Effect.forEach(networkTwo, (twoUser) => | ||
createAndImportUsersFromNetwork(twoUser, networkTwo) | ||
) | ||
) | ||
}) | ||
) | ||
}) | ||
|
||
describe('Common connections', () => { | ||
it('Fetches common connections for array of friends', async () => { | ||
await runPromiseInMockedEnvironment( | ||
Effect.gen(function* (_) { | ||
const app = yield* _(NodeTestingApp) | ||
|
||
const me = networkOne[0] | ||
const userContacts = Array.filter( | ||
networkOne, | ||
(u) => u.keys.publicKeyPemBase64 !== me.keys.publicKeyPemBase64 | ||
) | ||
|
||
const connections = yield* _( | ||
app.fetchCommonConnections( | ||
{ | ||
body: { | ||
publicKeys: Array.map( | ||
userContacts, | ||
(one) => one.keys.publicKeyPemBase64 | ||
), | ||
}, | ||
}, | ||
HttpClientRequest.setHeaders(networkOne[0].authHeaders) | ||
) | ||
) | ||
|
||
const resultKeys = pipe( | ||
connections.commonContacts, | ||
Array.map((c) => c.publicKey), | ||
Array.sort(Order.string), | ||
Array.join(', ') | ||
) | ||
// Result keys equals to requestzdcgtrfdcdfgtzrcfedxs | ||
expect(resultKeys).toBe( | ||
pipe( | ||
userContacts, | ||
Array.map((o) => o.keys.publicKeyPemBase64), | ||
Array.sort(Order.string), | ||
Array.join(', ') | ||
) | ||
) | ||
|
||
// Each friend should have other people as common friends | ||
for (const {common, publicKey} of connections.commonContacts) { | ||
const otherFriendsHashes = pipe( | ||
userContacts, | ||
Array.filter((o) => o.keys.publicKeyPemBase64 !== publicKey), | ||
Array.map((o) => o.hashedNumber), | ||
Array.sort(Order.string), | ||
Array.join(',') | ||
) | ||
|
||
expect( | ||
pipe(common.hashes, Array.sort(Order.string), Array.join(',')) | ||
).toEqual(otherFriendsHashes) | ||
} | ||
}) | ||
) | ||
}) | ||
}) |
172 changes: 172 additions & 0 deletions
172
apps/contact-service/src/__tests__/utils/routes/contacts/fetchMyContacts.test.ts
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,172 @@ | ||
import {HttpClientRequest} from '@effect/platform' | ||
import {MAX_PAGE_SIZE} from '@vexl-next/rest-api/src/Pagination.brand' | ||
import {Array, Effect, Order, pipe} from 'effect' | ||
import {NodeTestingApp} from '../../NodeTestingApp' | ||
import {runPromiseInMockedEnvironment} from '../../runPromiseInMockedEnvironment' | ||
import { | ||
createAndImportUsersFromNetwork, | ||
type DummyUser, | ||
generateKeysAndHasheForNumber, | ||
} from './utils' | ||
|
||
let networkOne: [DummyUser, ...DummyUser[]] | ||
let networkTwo: [DummyUser, ...DummyUser[]] | ||
|
||
beforeAll(async () => { | ||
await runPromiseInMockedEnvironment( | ||
Effect.gen(function* (_) { | ||
networkOne = yield* _( | ||
Effect.all([ | ||
generateKeysAndHasheForNumber('+420733333001'), | ||
generateKeysAndHasheForNumber('+420733333002'), | ||
generateKeysAndHasheForNumber('+420733333003'), | ||
generateKeysAndHasheForNumber('+420733333004'), | ||
generateKeysAndHasheForNumber('+420733333005'), | ||
]) | ||
) | ||
|
||
yield* _( | ||
Effect.forEach(networkOne, (oneUser) => | ||
createAndImportUsersFromNetwork(oneUser, networkOne) | ||
) | ||
) | ||
|
||
networkTwo = yield* _( | ||
Effect.all([ | ||
generateKeysAndHasheForNumber('+420733333101'), | ||
generateKeysAndHasheForNumber('+420733333102'), | ||
generateKeysAndHasheForNumber('+420733333106'), | ||
generateKeysAndHasheForNumber('+420733333107'), | ||
generateKeysAndHasheForNumber('+420733333108'), | ||
]) | ||
) | ||
|
||
yield* _( | ||
Effect.forEach(networkTwo, (twoUser) => | ||
createAndImportUsersFromNetwork(twoUser, [ | ||
// ...networkTwo, | ||
...networkOne, | ||
]) | ||
) | ||
) | ||
}) | ||
) | ||
}) | ||
|
||
describe('Fetch my contacts', () => { | ||
it('Properly fetches first level contacts', async () => { | ||
await runPromiseInMockedEnvironment( | ||
Effect.gen(function* (_) { | ||
const me = networkOne[0] | ||
|
||
const userContacts = Array.filter( | ||
networkOne, | ||
(u) => u.keys.publicKeyPemBase64 !== me.keys.publicKeyPemBase64 | ||
) | ||
const app = yield* _(NodeTestingApp) | ||
const {items} = yield* _( | ||
app.fetchMyContacts( | ||
{ | ||
query: {level: 'FIRST' as const, page: 0, limit: MAX_PAGE_SIZE}, | ||
}, | ||
HttpClientRequest.setHeaders(networkOne[0].authHeaders) | ||
) | ||
) | ||
|
||
expect( | ||
pipe( | ||
items, | ||
Array.map((o) => o.publicKey), | ||
Array.sort(Order.string), | ||
Array.join(',') | ||
) | ||
).toBe( | ||
pipe( | ||
userContacts, | ||
Array.map((one) => one.keys.publicKeyPemBase64), | ||
Array.sort(Order.string), | ||
Array.join(',') | ||
) | ||
) | ||
}) | ||
) | ||
}) | ||
it('Propely fetches second level contacts', async () => { | ||
await runPromiseInMockedEnvironment( | ||
Effect.gen(function* (_) { | ||
const me = networkOne[0] | ||
const userContacts = Array.filter( | ||
networkOne, | ||
(u) => u.keys.publicKeyPemBase64 !== me.keys.publicKeyPemBase64 | ||
) | ||
|
||
const app = yield* _(NodeTestingApp) | ||
const {items} = yield* _( | ||
app.fetchMyContacts( | ||
{ | ||
query: {level: 'SECOND' as const, page: 0, limit: MAX_PAGE_SIZE}, | ||
}, | ||
HttpClientRequest.setHeaders(me.authHeaders) | ||
) | ||
) | ||
|
||
console.log('me', me.keys.publicKeyPemBase64) | ||
|
||
expect( | ||
pipe( | ||
items, | ||
Array.map((o) => o.publicKey), | ||
Array.sort(Order.string), | ||
Array.join(',') | ||
) | ||
).toBe( | ||
pipe( | ||
[...networkTwo, ...userContacts], | ||
Array.map((one) => one.keys.publicKeyPemBase64), | ||
Array.sort(Order.string), | ||
Array.join(',') | ||
) | ||
) | ||
}) | ||
) | ||
}) | ||
it('Properly fetches all level contacts', async () => { | ||
await runPromiseInMockedEnvironment( | ||
Effect.gen(function* (_) { | ||
const me = networkOne[0] | ||
const userContacts = Array.filter( | ||
networkOne, | ||
(u) => u.keys.publicKeyPemBase64 !== me.keys.publicKeyPemBase64 | ||
) | ||
|
||
const app = yield* _(NodeTestingApp) | ||
const {items} = yield* _( | ||
app.fetchMyContacts( | ||
{ | ||
query: {level: 'ALL' as const, page: 0, limit: MAX_PAGE_SIZE}, | ||
}, | ||
HttpClientRequest.setHeaders(me.authHeaders) | ||
) | ||
) | ||
|
||
console.log('me', me.keys.publicKeyPemBase64) | ||
|
||
expect( | ||
pipe( | ||
items, | ||
Array.map((o) => o.publicKey), | ||
Array.sort(Order.string), | ||
Array.join(',') | ||
) | ||
).toBe( | ||
pipe( | ||
[...networkTwo, ...userContacts], | ||
Array.map((one) => one.keys.publicKeyPemBase64), | ||
Array.sort(Order.string), | ||
Array.join(',') | ||
) | ||
) | ||
}) | ||
) | ||
}) | ||
}) |
Oops, something went wrong.