|
15 | 15 | * limitations under the License.
|
16 | 16 | */
|
17 | 17 | import { expect, use } from "chai";
|
18 |
| -import { GoogleAIFileManager } from "./file-manager"; |
| 18 | +import { GoogleAIFileManager, getUploadMetadata } from "./file-manager"; |
19 | 19 | import * as sinonChai from "sinon-chai";
|
20 | 20 | import * as chaiAsPromised from "chai-as-promised";
|
21 | 21 | import { restore, stub } from "sinon";
|
22 | 22 | import * as request from "./request";
|
23 | 23 | import { FilesTask } from "./constants";
|
24 | 24 | import { DEFAULT_API_VERSION } from "../requests/request";
|
| 25 | +import { FileMetadata } from "./types"; |
25 | 26 |
|
26 | 27 | use(sinonChai);
|
27 | 28 | use(chaiAsPromised);
|
@@ -254,4 +255,38 @@ describe("GoogleAIFileManager", () => {
|
254 | 255 | "Invalid fileId",
|
255 | 256 | );
|
256 | 257 | });
|
| 258 | + |
| 259 | + describe("getUploadMetadata", () => { |
| 260 | + it("getUploadMetadata with only mimeType", () => { |
| 261 | + const uploadMetadata = getUploadMetadata({ mimeType: "image/jpeg" }); |
| 262 | + expect(uploadMetadata.mimeType).to.equal("image/jpeg"); |
| 263 | + expect(uploadMetadata.displayName).be.undefined; |
| 264 | + expect(uploadMetadata.name).be.undefined; |
| 265 | + }); |
| 266 | + it("getUploadMetadata with no mimeType", () => { |
| 267 | + expect(() => getUploadMetadata({} as FileMetadata)).to.throw( |
| 268 | + "Must provide a mimeType.", |
| 269 | + ); |
| 270 | + }); |
| 271 | + it("getUploadMetadata with all fields defined", () => { |
| 272 | + const uploadMetadata = getUploadMetadata({ |
| 273 | + mimeType: "image/jpeg", |
| 274 | + displayName: "display name", |
| 275 | + name: "filename", |
| 276 | + }); |
| 277 | + expect(uploadMetadata.mimeType).to.equal("image/jpeg"); |
| 278 | + expect(uploadMetadata.displayName).to.equal("display name"); |
| 279 | + expect(uploadMetadata.name).to.equal("files/filename"); |
| 280 | + }); |
| 281 | + it("getUploadMetadata with full file path", () => { |
| 282 | + const uploadMetadata = getUploadMetadata({ |
| 283 | + mimeType: "image/jpeg", |
| 284 | + displayName: "display name", |
| 285 | + name: "custom/path/filename", |
| 286 | + }); |
| 287 | + expect(uploadMetadata.mimeType).to.equal("image/jpeg"); |
| 288 | + expect(uploadMetadata.displayName).to.equal("display name"); |
| 289 | + expect(uploadMetadata.name).to.equal("custom/path/filename"); |
| 290 | + }); |
| 291 | + }); |
257 | 292 | });
|
0 commit comments