Skip to content

Commit c234c2e

Browse files
committed
Reorganize tests in prep for adding more
1 parent a571f70 commit c234c2e

File tree

17 files changed

+1263
-1100
lines changed

17 files changed

+1263
-1100
lines changed

src/__fixtures__/credentials.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { Credential, AccessToken } from '../main';
2+
3+
export const testCredential: Credential = {
4+
authEntity: 'test-entity',
5+
type: 'api-key',
6+
payload: 'test-payload',
7+
};
8+
9+
export const differentCredential: Credential = {
10+
authEntity: 'different-entity',
11+
type: 'api-key',
12+
payload: 'different-payload',
13+
};
14+
15+
export const testAccessToken: AccessToken = {
16+
type: 'access-token',
17+
payload: 'test-access-token',
18+
};
19+
20+
export const differentAccessToken: AccessToken = {
21+
type: 'access-token',
22+
payload: 'different-access-token',
23+
};
24+

src/__fixtures__/test-constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const TEST_URL = 'http://base.test';
2+
export const TEST_HOST = 'test-host';
3+
export const TEST_AUTH_ENTITY = 'test-entity';
4+
export const TEST_SIGNALING_ADDRESS = 'https://signaling.test';
5+

src/__mocks__/transports.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { Transport } from '@connectrpc/connect';
2+
import { vi } from 'vitest';
3+
4+
export const createMockTransport = (): Transport => {
5+
return {
6+
unary: vi.fn(),
7+
stream: vi.fn(),
8+
} satisfies Transport;
9+
};

src/__mocks__/webrtc.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { vi } from 'vitest';
2+
3+
export const createMockPeerConnection = (
4+
closeFn = vi.fn(),
5+
addEventListenerFn = vi.fn(),
6+
removeEventListenerFn = vi.fn(),
7+
iceConnectionState: RTCIceConnectionState = 'connected'
8+
): RTCPeerConnection => {
9+
return {
10+
close: closeFn,
11+
addEventListener: addEventListenerFn,
12+
removeEventListener: removeEventListenerFn,
13+
iceConnectionState,
14+
} as unknown as RTCPeerConnection;
15+
};
16+
17+
export const createMockDataChannel = (
18+
closeFn = vi.fn(),
19+
addEventListenerFn = vi.fn(),
20+
removeEventListenerFn = vi.fn(),
21+
readyState: RTCDataChannelState = 'open'
22+
): RTCDataChannel => {
23+
return {
24+
close: closeFn,
25+
addEventListener: addEventListenerFn,
26+
removeEventListener: removeEventListenerFn,
27+
readyState,
28+
} as unknown as RTCDataChannel;
29+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {
2+
TEST_HOST,
3+
TEST_SIGNALING_ADDRESS,
4+
} from '../../__fixtures__/test-constants';
5+
import type { DialConf } from '../../main';
6+
7+
export const baseDialConfig: DialConf = {
8+
host: TEST_HOST,
9+
signalingAddress: TEST_SIGNALING_ADDRESS,
10+
} as const;
11+
12+
export const withDisableSessions: DialConf = {
13+
...baseDialConfig,
14+
disableSessions: true,
15+
} as const;
16+
17+
export const withNoReconnect: DialConf = {
18+
...baseDialConfig,
19+
noReconnect: true,
20+
} as const;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { createRouterTransport, type Transport } from '@connectrpc/connect';
2+
import { RobotService } from '../../gen/robot/v1/robot_connect';
3+
import type { PartialMessage } from '@bufbuild/protobuf';
4+
import type { Operation } from '../../gen/robot/v1/robot_pb';
5+
import type { ResourceName } from '../../gen/common/v1/common_pb';
6+
7+
export const createMockRobotServiceTransport = (
8+
resources: PartialMessage<ResourceName>[] = [],
9+
operations: PartialMessage<Operation>[] = []
10+
): Transport => {
11+
return createRouterTransport(({ service }) => {
12+
service(RobotService, {
13+
resourceNames: () => ({ resources }),
14+
getOperations: () => ({ operations }),
15+
});
16+
});
17+
};

0 commit comments

Comments
 (0)