forked from connectrpc/examples-es
-
Notifications
You must be signed in to change notification settings - Fork 0
/
url-shortener.test.ts
26 lines (25 loc) · 1 KB
/
url-shortener.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { after, it } from 'node:test';
import assert from 'node:assert';
import { Miniflare } from 'miniflare';
import { UrlShortenerService } from './gen/urlshortener/v1/urlshortener_connect.js';
import { createConnectTransport } from '@connectrpc/connect-node';
import { createPromiseClient } from '@connectrpc/connect';
it('should shorten and expand', async () => {
const mf = new Miniflare({
scriptPath: './dist/index.js',
modules: true,
kvNamespaces: ['STORE'],
compatibilityDate: '2023-10-02', // REQUIRED for using ReadableStream
});
after(() => mf.dispose());
const baseUrl = (await mf.ready).toString().slice(0, -1);
const transport = createConnectTransport({
baseUrl: baseUrl,
httpVersion: '1.1',
useBinaryFormat: true,
});
const client = createPromiseClient(UrlShortenerService, transport);
const { url: shortUrl } = await client.shorten({ url: 'https://google.com' });
const { url: longUrl } = await client.expand({ url: shortUrl });
assert.strictEqual(longUrl, 'https://google.com');
});