forked from imxeno/trpc-rabbitmq
-
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.
feat(test): implement automatic testing
- Loading branch information
1 parent
0f11060
commit 544ddf1
Showing
5 changed files
with
85 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Aedes from 'aedes'; | ||
import { createServer } from 'net'; | ||
|
||
const aedes = new Aedes(); | ||
const server = createServer(aedes.handle); | ||
|
||
server.listen(1883, () => { | ||
console.log('server started and listening on port 1883'); | ||
}); |
This file was deleted.
Oops, something went wrong.
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,64 @@ | ||
import { createTRPCProxyClient } from '@trpc/client'; | ||
import Aedes from 'aedes'; | ||
import { once } from 'events'; | ||
import mqtt from 'mqtt'; | ||
import { createServer } from 'net'; | ||
|
||
import { createMQTTHandler } from '../src/adapter'; | ||
import { mqttLink } from '../src/link'; | ||
import { AppRouter, appRouter } from './appRouter'; | ||
|
||
const requestTopic = 'rpc/request'; | ||
|
||
const aedes = new Aedes(); | ||
// aedes.on('publish', (packet, client) => console.log(packet.topic, packet.payload.toString())); | ||
const broker = createServer(aedes.handle); | ||
broker.listen(1883); | ||
const mqttClient = mqtt.connect('mqtt://localhost'); | ||
|
||
createMQTTHandler({ | ||
client: mqttClient, | ||
requestTopic, | ||
router: appRouter | ||
}); | ||
|
||
const client = createTRPCProxyClient<AppRouter>({ | ||
links: [ | ||
mqttLink({ | ||
client: mqttClient, | ||
requestTopic | ||
}) | ||
] | ||
}); | ||
|
||
beforeAll(async () => { | ||
await once(broker, 'listening'); | ||
await once(mqttClient, 'connect'); | ||
}); | ||
|
||
test('broker is listening', () => { | ||
expect(broker.listening).toBe(true); | ||
}); | ||
|
||
test('mqtt client is connected', () => { | ||
expect(mqttClient.connected).toBe(true); | ||
}); | ||
|
||
test('greet query', async () => { | ||
const greeting = await client.greet.query('world'); | ||
expect(greeting).toEqual({ greeting: 'hello, world!' }); | ||
}); | ||
|
||
test('countUp mutation', async () => { | ||
const addOne = await client.countUp.mutate(1); | ||
expect(addOne).toBe(1); | ||
|
||
const addTwo = await client.countUp.mutate(2); | ||
expect(addTwo).toBe(3); | ||
}); | ||
|
||
afterAll(async () => { | ||
mqttClient.end(); | ||
broker.close(); | ||
aedes.close(); | ||
}); |
This file was deleted.
Oops, something went wrong.