Skip to content

Commit 2a533d0

Browse files
authored
Merge pull request #44 from polywrap/nk/aggregator-resolver-test
feat: add aggregator-resolver test-cases
2 parents ec2a1ec + 2e5fc07 commit 2a533d0

4 files changed

Lines changed: 120 additions & 0 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import {
2+
Uri,
3+
UriResolutionContext,
4+
} from "@polywrap/core-js";
5+
import { expectHistory } from "../helpers/expectHistory";
6+
import { PolywrapCoreClient } from "@polywrap/core-client-js";
7+
import { UriResolverAggregator } from "../../aggregator";
8+
9+
jest.setTimeout(20000);
10+
11+
describe("UriResolverAggregator", () => {
12+
const client = new PolywrapCoreClient({
13+
resolver: new UriResolverAggregator([
14+
{
15+
from: Uri.from("test/1"),
16+
to: Uri.from("test/2")
17+
},
18+
{
19+
from: Uri.from("test/2"),
20+
to: Uri.from("test/3")
21+
},
22+
{
23+
from: Uri.from("test/3"),
24+
to: Uri.from("test/4")
25+
}
26+
], "TestAggregator")
27+
});
28+
29+
it("can resolve using first resolver", async () => {
30+
const uri = new Uri("test/1");
31+
32+
let resolutionContext = new UriResolutionContext();
33+
let result = await client.tryResolveUri({ uri, resolutionContext });
34+
35+
await expectHistory(
36+
resolutionContext.getHistory(),
37+
"aggregator-resolver",
38+
"can-resolve-using-first-resolver",
39+
);
40+
41+
if (!result.ok) {
42+
fail(result.error);
43+
}
44+
45+
if (result.value.type !== "uri") {
46+
fail("Expected a uri, received: " + result.value.type);
47+
}
48+
49+
expect(result.value.uri.uri).toEqual("wrap://test/2");
50+
});
51+
52+
it("can resolve using last resolver", async () => {
53+
const uri = new Uri("test/3");
54+
55+
let resolutionContext = new UriResolutionContext();
56+
let result = await client.tryResolveUri({ uri, resolutionContext });
57+
58+
await expectHistory(
59+
resolutionContext.getHistory(),
60+
"aggregator-resolver",
61+
"can-resolve-using-last-resolver",
62+
);
63+
64+
if (!result.ok) {
65+
fail(result.error);
66+
}
67+
68+
if (result.value.type !== "uri") {
69+
fail("Expected a uri, received: " + result.value.type);
70+
}
71+
72+
expect(result.value.uri.uri).toEqual("wrap://test/4");
73+
});
74+
75+
76+
it("does not resolve a uri when not a match", async () => {
77+
const uri = new Uri("test/not-a-match");
78+
79+
let resolutionContext = new UriResolutionContext();
80+
let result = await client.tryResolveUri({ uri, resolutionContext });
81+
82+
await expectHistory(
83+
resolutionContext.getHistory(),
84+
"aggregator-resolver",
85+
"not-a-match",
86+
);
87+
88+
if (!result.ok) {
89+
fail(result.error);
90+
}
91+
92+
if (result.value.type !== "uri") {
93+
fail("Expected a uri, received: " + result.value.type);
94+
}
95+
96+
expect(result.value.uri.uri).toEqual("wrap://test/not-a-match");
97+
});
98+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
"wrap://test/1 => TestAggregator => uri (wrap://test/2)",
3+
[
4+
"wrap://test/1 => Redirect (wrap://test/1 - wrap://test/2) => uri (wrap://test/2)"
5+
]
6+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
"wrap://test/3 => TestAggregator => uri (wrap://test/4)",
3+
[
4+
"wrap://test/3 => Redirect (wrap://test/1 - wrap://test/2)",
5+
"wrap://test/3 => Redirect (wrap://test/2 - wrap://test/3)",
6+
"wrap://test/3 => Redirect (wrap://test/3 - wrap://test/4) => uri (wrap://test/4)"
7+
]
8+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
"wrap://test/not-a-match => TestAggregator",
3+
[
4+
"wrap://test/not-a-match => Redirect (wrap://test/1 - wrap://test/2)",
5+
"wrap://test/not-a-match => Redirect (wrap://test/2 - wrap://test/3)",
6+
"wrap://test/not-a-match => Redirect (wrap://test/3 - wrap://test/4)"
7+
]
8+
]

0 commit comments

Comments
 (0)