/
areaCalculatorClientTest.ts
68 lines (65 loc) 路 1.82 KB
/
areaCalculatorClientTest.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import {
assertEquals,
DenoPact,
getModuleDir,
Pact,
path,
} from "../deps.dev.ts";
// } from "../deps.ts";
import { getShapeMessage } from "./areaCalculator/areaCalculatorClient.ts";
const protoPath = path.join(
getModuleDir(import.meta),
"areaCalculator",
"area_calculator.proto",
);
Deno.test(
{
name: "Greeter/SayHello Unary gRPC test",
sanitizeResources: false,
sanitizeOps: false,
},
async () => {
const denoPact = new DenoPact();
const pactContents = {
"pact:proto": protoPath,
"pact:proto-service": "Calculator/calculateOne",
"pact:content-type": "application/protobuf",
request: {
rectangle: {
length: "matching(number, 3)",
width: "matching(number, 4)",
},
},
response: { value: ["matching(number, 12)"] },
};
console.log(
"馃殌 Testing gRPC Area Calculator with Pact Protobuf Plugin 馃殌\n",
{
pactContents,
},
);
await denoPact
.setupLoggers()
// Arrange
.newPact("area-calculator-consumer", "area-calculator-provider")
.addMetaDataToPact(denoPact.getPactFfiVersion())
.newSyncMessageInteraction("A gRPC calculateOne request")
.setPactSpecification(Pact.PactSpecification.PactSpecification_V4)
.usingPactPlugin("protobuf")
.withInteractionContents(
Pact.InteractionPart.InteractionPart_Request,
"application/grpc",
pactContents,
)
.createMockServerForTransport("grpc")
.executeTest(async () => {
const expected = [12];
// Act
const mockServerPort = denoPact.getMockServerPort();
const results = await getShapeMessage(mockServerPort);
// Assert
assertEquals(results.value, expected);
})
.then((results: string) => console.log(results));
},
);