[mod]
This commit is contained in:
39
backend1/test/api/ApiSend.test.ts
Normal file
39
backend1/test/api/ApiSend.test.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import assert from "assert";
|
||||
import { TsrpcError, WsClient } from "tsrpc";
|
||||
import { serviceProto, ServiceType } from "../../src/shared/protocols/serviceProto";
|
||||
|
||||
// 1. EXECUTE `npm run dev` TO START A LOCAL DEV SERVER
|
||||
// 2. EXECUTE `npm test` TO START UNIT TEST
|
||||
|
||||
describe("ApiSend", function (): void {
|
||||
let client: WsClient<ServiceType> = new WsClient(serviceProto, {
|
||||
server: "ws://127.0.0.1:3000",
|
||||
logger: console
|
||||
});
|
||||
|
||||
before(async function (): Promise<void> {
|
||||
let res: any = await client.connect();
|
||||
assert.strictEqual(res.isSucc, true, "Failed to connect to server, have you executed `npm run dev` already?");
|
||||
});
|
||||
|
||||
it("Success", async function (): Promise<void> {
|
||||
let ret: any = await client.callApi("Join", {
|
||||
content: "Test"
|
||||
});
|
||||
assert.ok(ret.isSucc);
|
||||
});
|
||||
|
||||
it("Check content is empty", async function (): Promise<void> {
|
||||
let ret: any = await client.callApi("Join", {
|
||||
content: ""
|
||||
});
|
||||
assert.deepStrictEqual(ret, {
|
||||
isSucc: false,
|
||||
err: new TsrpcError("Content is empty")
|
||||
});
|
||||
});
|
||||
|
||||
after(async function (): Promise<void> {
|
||||
await client.disconnect();
|
||||
});
|
||||
});
|
15
backend1/test/tsconfig.json
Normal file
15
backend1/test/tsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"lib": [
|
||||
"es2018"
|
||||
],
|
||||
"module": "commonjs",
|
||||
"target": "es2018",
|
||||
"outDir": "dist",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"moduleResolution": "node"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user