Skip to content

Commit c243141

Browse files
committed
relocate custom funcs and their tests
1 parent bc450fd commit c243141

File tree

7 files changed

+70
-16
lines changed

7 files changed

+70
-16
lines changed

.speakeasy/workflow.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ targets:
1111
openrouter:
1212
source: OpenRouter API
1313
sourceNamespace: open-router-chat-completions-api
14-
sourceRevisionDigest: sha256:c2e2e5da1b9a37b494867bb17c7bb41a4959ceeafd85543abc062675303a6e0c
15-
sourceBlobDigest: sha256:598248a264c5fac83e1bbae64cf68a4a95f6213b95bd17917299b192604c72c7
14+
sourceRevisionDigest: sha256:4e400d0ed413626f503b2f9662518aef3c7a8ca9ab30d7027f0580b94242e77c
15+
sourceBlobDigest: sha256:f18b355f07b1593cc10f1b09fe0f5dbbc1225f16d5d8f250bec0bc9b6e6611db
1616
workflow:
1717
workflowVersion: 1.0.0
1818
speakeasyVersion: latest

src/funcs/custom/oAuthCreateAuthorizationUrl.ts renamed to src/funcs/oAuthCreateAuthorizationUrl.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import z from "zod/v3";
2-
import { OpenRouterCore } from "../../core.js";
3-
import { serverURLFromOptions } from "../../lib/config.js";
4-
import { Result } from "../../types/fp.js";
2+
import { OpenRouterCore } from "../core.js";
3+
import { serverURLFromOptions } from "../lib/config.js";
4+
import { Result } from "../types/fp.js";
55

66
const CreateAuthorizationUrlBaseSchema = z.object({
77
callbackUrl: z.union([z.string().url(), z.instanceof(URL)]),

src/funcs/custom/oAuthCreateSHA256CodeChallenge.ts renamed to src/funcs/oAuthCreateSHA256CodeChallenge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import z from "zod/v3";
2-
import { Result } from "../../types/fp.js";
2+
import { Result } from "../types/fp.js";
33

44
const CreateSHA256CodeChallengeRequestSchema = z.object({
55
/**

src/sdk/oauth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import { unwrapAsync } from "../types/fp.js";
1111
import {
1212
CreateAuthorizationUrlRequest,
1313
oAuthCreateAuthorizationUrl,
14-
} from "../funcs/custom/oAuthCreateAuthorizationUrl.js";
14+
} from "../funcs/oAuthCreateAuthorizationUrl.js";
1515
import {
1616
CreateSHA256CodeChallengeRequest,
1717
CreateSHA256CodeChallengeResponse,
1818
oAuthCreateSHA256CodeChallenge,
19-
} from "../funcs/custom/oAuthCreateSHA256CodeChallenge.js";
19+
} from "../funcs/oAuthCreateSHA256CodeChallenge.js";
2020
// #endregion imports
2121

2222
export class OAuth extends ClientSDK {

src/funcs/custom/oAuthCreateAuthorizationUrl.test.ts renamed to tests/funcs/oAuthCreateAuthorizationUrl.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, expect } from "vitest";
2-
import { OpenRouterCore } from "../../core.js";
3-
import { oAuthCreateAuthorizationUrl } from "./oAuthCreateAuthorizationUrl.js";
2+
import { OpenRouterCore } from "../../src/core";
3+
import { oAuthCreateAuthorizationUrl } from "../../src/funcs/oAuthCreateAuthorizationUrl";
44

55
describe("oAuthCreateAuthorizationUrl", () => {
66
const createMockClient = (serverURL?: string) => {

src/funcs/custom/oAuthCreateSHA256CodeChallenge.test.ts renamed to tests/funcs/oAuthCreateSHA256CodeChallenge.test.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect } from "vitest";
2-
import { oAuthCreateSHA256CodeChallenge } from "./oAuthCreateSHA256CodeChallenge.js";
2+
import { oAuthCreateSHA256CodeChallenge } from "../../src/funcs/oAuthCreateSHA256CodeChallenge";
33

44
describe("oAuthCreateSHA256CodeChallenge", () => {
55
it("should generate code challenge from provided code verifier", async () => {
@@ -101,7 +101,9 @@ describe("oAuthCreateSHA256CodeChallenge", () => {
101101
expect(result.ok).toBe(false);
102102
if (!result.ok) {
103103
expect(result.error).toBeDefined();
104-
expect((result.error as Error).message).toContain("at least 43 characters");
104+
expect((result.error as Error).message).toContain(
105+
"at least 43 characters",
106+
);
105107
}
106108
});
107109

@@ -113,7 +115,9 @@ describe("oAuthCreateSHA256CodeChallenge", () => {
113115
expect(result.ok).toBe(false);
114116
if (!result.ok) {
115117
expect(result.error).toBeDefined();
116-
expect((result.error as Error).message).toContain("at least 43 characters");
118+
expect((result.error as Error).message).toContain(
119+
"at least 43 characters",
120+
);
117121
}
118122
});
119123

@@ -126,7 +130,9 @@ describe("oAuthCreateSHA256CodeChallenge", () => {
126130
expect(result.ok).toBe(false);
127131
if (!result.ok) {
128132
expect(result.error).toBeDefined();
129-
expect((result.error as Error).message).toContain("at most 128 characters");
133+
expect((result.error as Error).message).toContain(
134+
"at most 128 characters",
135+
);
130136
}
131137
});
132138

@@ -170,7 +176,9 @@ describe("oAuthCreateSHA256CodeChallenge", () => {
170176
expect(result.ok).toBe(false);
171177
if (!result.ok) {
172178
expect(result.error).toBeDefined();
173-
expect((result.error as Error).message).toContain("unreserved characters");
179+
expect((result.error as Error).message).toContain(
180+
"unreserved characters",
181+
);
174182
}
175183
});
176184

@@ -183,7 +191,9 @@ describe("oAuthCreateSHA256CodeChallenge", () => {
183191
expect(result.ok).toBe(false);
184192
if (!result.ok) {
185193
expect(result.error).toBeDefined();
186-
expect((result.error as Error).message).toContain("unreserved characters");
194+
expect((result.error as Error).message).toContain(
195+
"unreserved characters",
196+
);
187197
}
188198
});
189199
});

tests/sdk/oauth.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { describe, expect, it, vi } from "vitest";
2+
import { OAuth as OpenRouterOAuthSDK } from "../../src/sdk/oauth";
3+
4+
describe("oauth", () => {
5+
const oauthSdkInstance = new OpenRouterOAuthSDK({
6+
serverURL: "https://test-server-url",
7+
});
8+
9+
describe("createSHA256CodeChallenge", () => {
10+
it("is defined on the oauth sdk object", () => {
11+
expect(oauthSdkInstance.createSHA256CodeChallenge).toBeDefined();
12+
});
13+
14+
it("calls the custom oAuthCreateSHA256CodeChallenge function", async () => {
15+
const spy = vi.spyOn(
16+
await import("../../src/funcs/oAuthCreateSHA256CodeChallenge"),
17+
"oAuthCreateSHA256CodeChallenge",
18+
);
19+
20+
oauthSdkInstance.createSHA256CodeChallenge();
21+
22+
expect(spy).toHaveBeenCalled();
23+
});
24+
});
25+
26+
describe("createAuthorizationUrl", () => {
27+
it("is defined on the oauth sdk object", () => {
28+
expect(oauthSdkInstance.createAuthorizationUrl).toBeDefined();
29+
});
30+
31+
it("calls the custom oAuthCreateAuthorizationUrl function", async () => {
32+
const spy = vi.spyOn(
33+
await import("../../src/funcs/oAuthCreateAuthorizationUrl"),
34+
"oAuthCreateAuthorizationUrl",
35+
);
36+
37+
oauthSdkInstance.createAuthorizationUrl({
38+
callbackUrl: "https://example.com/callback",
39+
});
40+
41+
expect(spy).toHaveBeenCalled();
42+
});
43+
});
44+
});

0 commit comments

Comments
 (0)