Skip to content

Commit f50898a

Browse files
committed
feat: add remaining test-cases
1 parent 86f849c commit f50898a

4 files changed

Lines changed: 102 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
"wrap://test/package => StaticResolver - Package (wrap://test/package) => package (wrap://test/package)"
3+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
"wrap://test/wrapper => StaticResolver - Wrapper (wrap://test/wrapper) => wrapper (wrap://test/wrapper)"
3+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
"wrap://test/not-a-match => StaticResolver - Miss"
3+
]

packages/uri-resolvers/src/__tests__/static-resolver/static-resolver.spec.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {
2+
IWrapPackage,
23
Uri,
34
UriResolutionContext,
5+
Wrapper,
46
} from "@polywrap/core-js";
57
import { expectHistory } from "../helpers/expectHistory";
68
import { PolywrapCoreClient } from "@polywrap/core-client-js";
@@ -40,4 +42,95 @@ describe("StaticResolver", () => {
4042

4143
expect(result.value.uri.uri).toEqual("wrap://test/to");
4244
});
45+
46+
it("can resolve a package", async () => {
47+
const uri = new Uri("test/package");
48+
49+
const client = new PolywrapCoreClient({
50+
resolver: StaticResolver.from([
51+
{
52+
uri: Uri.from("test/package"),
53+
package: {} as IWrapPackage,
54+
},
55+
]),
56+
});
57+
58+
let resolutionContext = new UriResolutionContext();
59+
let result = await client.tryResolveUri({ uri, resolutionContext });
60+
61+
await expectHistory(
62+
resolutionContext.getHistory(),
63+
"static-resolver",
64+
"can-resolve-a-package"
65+
);
66+
67+
if (!result.ok) {
68+
fail(result.error);
69+
}
70+
71+
if (result.value.type !== "package") {
72+
fail("Expected a package, received: " + result.value.type);
73+
}
74+
75+
expect(result.value.uri.uri).toEqual("wrap://test/package");
76+
});
77+
78+
it("can resolve a wrapper", async () => {
79+
const uri = new Uri("test/wrapper");
80+
81+
const client = new PolywrapCoreClient({
82+
resolver: StaticResolver.from([
83+
{
84+
uri: Uri.from("test/wrapper"),
85+
wrapper: {} as Wrapper,
86+
},
87+
]),
88+
});
89+
90+
let resolutionContext = new UriResolutionContext();
91+
let result = await client.tryResolveUri({ uri, resolutionContext });
92+
93+
await expectHistory(
94+
resolutionContext.getHistory(),
95+
"static-resolver",
96+
"can-resolve-a-wrapper"
97+
);
98+
99+
if (!result.ok) {
100+
fail(result.error);
101+
}
102+
103+
if (result.value.type !== "wrapper") {
104+
fail("Expected a wrapper, received: " + result.value.type);
105+
}
106+
107+
expect(result.value.uri.uri).toEqual("wrap://test/wrapper");
108+
});
109+
110+
it("can not resolve unregistered uri", async () => {
111+
const uri = new Uri("test/not-a-match");
112+
113+
const client = new PolywrapCoreClient({
114+
resolver: StaticResolver.from([]),
115+
});
116+
117+
let resolutionContext = new UriResolutionContext();
118+
let result = await client.tryResolveUri({ uri, resolutionContext });
119+
120+
await expectHistory(
121+
resolutionContext.getHistory(),
122+
"static-resolver",
123+
"not-a-match"
124+
);
125+
126+
if (!result.ok) {
127+
fail(result.error);
128+
}
129+
130+
if (result.value.type !== "uri") {
131+
fail("Expected a uri, received: " + result.value.type);
132+
}
133+
134+
expect(result.value.uri.uri).toEqual("wrap://test/not-a-match");
135+
});
43136
});

0 commit comments

Comments
 (0)