|
| 1 | +import { PollyClient } from "@aws-sdk/client-polly"; |
| 2 | +import { describe, expect, test as it } from "vitest"; |
| 3 | + |
| 4 | +import { getSynthesizeSpeechUrl } from "./index"; |
| 5 | + |
| 6 | +describe("polly-request-presigner", () => { |
| 7 | + it("should sign URLs", async () => { |
| 8 | + const url = await getSynthesizeSpeechUrl({ |
| 9 | + client: new PollyClient({ |
| 10 | + credentials: { |
| 11 | + accessKeyId: "INTEG", |
| 12 | + secretAccessKey: "INTEG", |
| 13 | + }, |
| 14 | + region: "us-east-1", |
| 15 | + }), |
| 16 | + params: { |
| 17 | + Text: "Hello world, the polly presigner is really cool!", |
| 18 | + OutputFormat: "mp3", |
| 19 | + VoiceId: "Kimberly", |
| 20 | + }, |
| 21 | + }); |
| 22 | + |
| 23 | + const urlSegments = url.split("&"); |
| 24 | + expect(urlSegments.sort()).toMatchObject([ |
| 25 | + "Text=Hello%20world%2C%20the%20polly%20presigner%20is%20really%20cool%21", |
| 26 | + "VoiceId=Kimberly", |
| 27 | + "X-Amz-Algorithm=AWS4-HMAC-SHA256", |
| 28 | + /X-Amz-Credential=(.*?)%2F(\d{8})%2Fus-east-1%2Fpolly%2Faws4_request/, |
| 29 | + /X-Amz-Date=\d{8}T\d+Z/, |
| 30 | + "X-Amz-Expires=3600", |
| 31 | + /X-Amz-Signature=(.*?)/, |
| 32 | + "X-Amz-SignedHeaders=host", |
| 33 | + "https://polly.us-east-1.amazonaws.com/v1/speech?OutputFormat=mp3", |
| 34 | + /x-amz-user-agent=aws-sdk-js%2F\d\.\d+\.\d+/, |
| 35 | + ]); |
| 36 | + }); |
| 37 | +}); |
0 commit comments