/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { expect, test } from "vitest"; import { Apideck } from "../index.js"; import { DownloadAcceptEnum, ExportAcceptEnum } from "../sdk/files.js"; import { filesToByteArray, streamToByteArray } from "./files.js"; import { createTestHTTPClient } from "./testclient.js"; test("Files File Storage Files All", async () => { const testHttpClient = createTestHTTPClient("fileStorage.filesAll"); const apideck = new Apideck({ serverURL: process.env["TEST_SERVER_URL"] ?? "http://localhost:18080", httpClient: testHttpClient, apiKey: process.env["APIDECK_API_KEY"] ?? "value", }); const result = await apideck.fileStorage.files.list({ consumerId: "test-consumer", appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX", serviceId: "salesforce", filter: { driveId: "1234", folderId: "root", shared: true, }, sort: { by: "updated_at", direction: "desc", }, passThrough: { "search": "San Francisco", }, fields: "id,updated_at", }); expect(result.httpMeta.response.status).toBe(200); expect(result.getFilesResponse).toBeDefined(); expect(result.getFilesResponse).toEqual({ statusCode: 200, status: "OK", service: "google-drive", resource: "files", operation: "all", data: [ { id: "12345", downstreamId: "12345", name: "sample.jpg", description: "A sample image", type: "file", path: "/Documents/sample.jpg", mimeType: "image/jpeg", size: 1810673, owner: { id: "12345", email: "hello@apideck.com", name: "Elon Musk", }, parentFolders: [ { id: "12345", name: "Personal", }, { id: "12345", name: "Personal", }, ], exportFormats: [ "application/pdf", "application/vnd.oasis.opendocument.presentation", "text/plain", ], updatedBy: "12345", createdBy: "12345", updatedAt: new Date("2020-09-30T07:43:32.000Z"), createdAt: new Date("2020-09-30T07:43:32.000Z"), }, { id: "12345", downstreamId: "12345", name: "sample.jpg", description: "A sample image", type: "file", path: "/Documents/sample.jpg", mimeType: "image/jpeg", size: 1810673, owner: { id: "12345", email: "hello@apideck.com", name: "Elon Musk", }, parentFolders: [ { id: "12345", name: "Personal", }, { id: "12345", name: "Personal", }, { id: "12345", name: "Personal", }, ], exportFormats: [ "application/pdf", "application/vnd.oasis.opendocument.presentation", "text/plain", ], updatedBy: "12345", createdBy: "12345", updatedAt: new Date("2020-09-30T07:43:32.000Z"), createdAt: new Date("2020-09-30T07:43:32.000Z"), }, { id: "12345", downstreamId: "12345", name: "sample.jpg", description: "A sample image", type: "file", path: "/Documents/sample.jpg", mimeType: "image/jpeg", size: 1810673, owner: { id: "12345", email: "hello@apideck.com", name: "Elon Musk", }, parentFolders: [ { id: "12345", name: "Personal", }, ], exportFormats: [ "application/pdf", "application/vnd.oasis.opendocument.presentation", "text/plain", ], updatedBy: "12345", createdBy: "12345", updatedAt: new Date("2020-09-30T07:43:32.000Z"), createdAt: new Date("2020-09-30T07:43:32.000Z"), }, ], meta: { itemsOnPage: 50, cursors: { previous: "em9oby1jcm06OnBhZ2U6OjE=", current: "em9oby1jcm06OnBhZ2U6OjI=", next: "em9oby1jcm06OnBhZ2U6OjM=", }, }, links: { previous: "https://unify.apideck.com/crm/companies?cursor=em9oby1jcm06OnBhZ2U6OjE%3D", current: "https://unify.apideck.com/crm/companies", next: "https://unify.apideck.com/crm/companies?cursor=em9oby1jcm06OnBhZ2U6OjM", }, }); }); test("Files File Storage Files Search", async () => { const testHttpClient = createTestHTTPClient("fileStorage.filesSearch"); const apideck = new Apideck({ serverURL: process.env["TEST_SERVER_URL"] ?? "http://localhost:18080", httpClient: testHttpClient, apiKey: process.env["APIDECK_API_KEY"] ?? "value", }); const result = await apideck.fileStorage.files.search({ consumerId: "test-consumer", appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX", serviceId: "salesforce", passThrough: { "search": "San Francisco", }, fields: "id,updated_at", filter: { driveId: "1234", folderId: "root", shared: true, }, filesSearch: { query: "logo jpg", }, }); expect(result.httpMeta.response.status).toBe(200); expect(result.getFilesResponse).toBeDefined(); expect(result.getFilesResponse).toEqual({ statusCode: 200, status: "OK", service: "google-drive", resource: "files", operation: "all", data: [ { id: "12345", downstreamId: "12345", name: "sample.jpg", description: "A sample image", type: "file", path: "/Documents/sample.jpg", mimeType: "image/jpeg", size: 1810673, owner: { id: "12345", email: "hello@apideck.com", name: "Elon Musk", }, parentFolders: [ { id: "12345", name: "Personal", }, { id: "12345", name: "Personal", }, ], exportFormats: [ "application/pdf", "application/vnd.oasis.opendocument.presentation", "text/plain", ], updatedBy: "12345", createdBy: "12345", updatedAt: new Date("2020-09-30T07:43:32.000Z"), createdAt: new Date("2020-09-30T07:43:32.000Z"), }, ], meta: { itemsOnPage: 50, cursors: { previous: "em9oby1jcm06OnBhZ2U6OjE=", current: "em9oby1jcm06OnBhZ2U6OjI=", next: "em9oby1jcm06OnBhZ2U6OjM=", }, }, links: { previous: "https://unify.apideck.com/crm/companies?cursor=em9oby1jcm06OnBhZ2U6OjE%3D", current: "https://unify.apideck.com/crm/companies", next: "https://unify.apideck.com/crm/companies?cursor=em9oby1jcm06OnBhZ2U6OjM", }, }); }); test("Files File Storage Files One", async () => { const testHttpClient = createTestHTTPClient("fileStorage.filesOne"); const apideck = new Apideck({ serverURL: process.env["TEST_SERVER_URL"] ?? "http://localhost:18080", httpClient: testHttpClient, apiKey: process.env["APIDECK_API_KEY"] ?? "value", }); const result = await apideck.fileStorage.files.get({ id: "", consumerId: "test-consumer", appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX", serviceId: "salesforce", fields: "id,updated_at", }); expect(result.httpMeta.response.status).toBe(200); expect(result.getFileResponse).toBeDefined(); expect(result.getFileResponse).toEqual({ statusCode: 200, status: "OK", service: "google-drive", resource: "files", operation: "one", data: { id: "12345", downstreamId: "12345", name: "sample.jpg", description: "A sample image", type: "file", path: "/Documents/sample.jpg", mimeType: "image/jpeg", size: 1810673, owner: { id: "12345", email: "hello@apideck.com", name: "Elon Musk", }, parentFolders: [ { id: "12345", name: "Personal", }, { id: "12345", name: "Personal", }, { id: "12345", name: "Personal", }, ], exportFormats: [ "application/pdf", "application/vnd.oasis.opendocument.presentation", "text/plain", ], updatedBy: "12345", createdBy: "12345", updatedAt: new Date("2020-09-30T07:43:32.000Z"), createdAt: new Date("2020-09-30T07:43:32.000Z"), }, }); }); test("Files File Storage Files Update", async () => { const testHttpClient = createTestHTTPClient("fileStorage.filesUpdate"); const apideck = new Apideck({ serverURL: process.env["TEST_SERVER_URL"] ?? "http://localhost:18080", httpClient: testHttpClient, apiKey: process.env["APIDECK_API_KEY"] ?? "value", }); const result = await apideck.fileStorage.files.update({ id: "", consumerId: "test-consumer", appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX", serviceId: "salesforce", updateFileRequest: { name: "New Name.pdf", description: "Renamed PDF Document", parentFolderId: "1234", passThrough: [ { serviceId: "", extendPaths: [ { path: "$.nested.property", value: { "TaxClassificationRef": { "value": "EUC-99990201-V1-00020000", }, }, }, { path: "$.nested.property", value: { "TaxClassificationRef": { "value": "EUC-99990201-V1-00020000", }, }, }, ], }, { serviceId: "", extendPaths: [ { path: "$.nested.property", value: { "TaxClassificationRef": { "value": "EUC-99990201-V1-00020000", }, }, }, { path: "$.nested.property", value: { "TaxClassificationRef": { "value": "EUC-99990201-V1-00020000", }, }, }, ], }, { serviceId: "", extendPaths: [ { path: "$.nested.property", value: { "TaxClassificationRef": { "value": "EUC-99990201-V1-00020000", }, }, }, { path: "$.nested.property", value: { "TaxClassificationRef": { "value": "EUC-99990201-V1-00020000", }, }, }, { path: "$.nested.property", value: { "TaxClassificationRef": { "value": "EUC-99990201-V1-00020000", }, }, }, ], }, ], }, }); expect(result.httpMeta.response.status).toBe(200); expect(result.updateFileResponse).toBeDefined(); expect(result.updateFileResponse).toEqual({ statusCode: 200, status: "OK", service: "google-drive", resource: "files", operation: "update", data: { id: "12345", }, }); }); test("Files File Storage Files Delete", async () => { const testHttpClient = createTestHTTPClient("fileStorage.filesDelete"); const apideck = new Apideck({ serverURL: process.env["TEST_SERVER_URL"] ?? "http://localhost:18080", httpClient: testHttpClient, apiKey: process.env["APIDECK_API_KEY"] ?? "value", }); const result = await apideck.fileStorage.files.delete({ id: "", consumerId: "test-consumer", appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX", serviceId: "salesforce", }); expect(result.httpMeta.response.status).toBe(200); expect(result.deleteFileResponse).toBeDefined(); expect(result.deleteFileResponse).toEqual({ statusCode: 200, status: "OK", service: "google-drive", resource: "files", operation: "delete", data: { id: "12345", }, }); }); test("Files File Storage Files Download", async () => { const testHttpClient = createTestHTTPClient("fileStorage.filesDownload"); const apideck = new Apideck({ serverURL: process.env["TEST_SERVER_URL"] ?? "http://localhost:18080", httpClient: testHttpClient, apiKey: process.env["APIDECK_API_KEY"] ?? "value", }); const result = await apideck.fileStorage.files.download({ id: "", consumerId: "test-consumer", appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX", serviceId: "salesforce", fields: "id,updated_at", }, { acceptHeaderOverride: DownloadAcceptEnum.wildcardRootWildcard, }); expect(result.httpMeta.response.status).toBe(200); expect(result.getFileDownloadResponse).toBeDefined(); expect( new Uint8Array(await streamToByteArray(result.getFileDownloadResponse)), ).toEqual(await filesToByteArray(".speakeasy/testfiles/example.file")); }); test("Files File Storage Files Export", async () => { const testHttpClient = createTestHTTPClient("fileStorage.filesExport"); const apideck = new Apideck({ serverURL: process.env["TEST_SERVER_URL"] ?? "http://localhost:18080", httpClient: testHttpClient, apiKey: process.env["APIDECK_API_KEY"] ?? "value", }); const result = await apideck.fileStorage.files.export({ id: "", consumerId: "test-consumer", appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX", serviceId: "salesforce", fields: "id,updated_at", format: "pdf", }, { acceptHeaderOverride: ExportAcceptEnum.wildcardRootWildcard, }); expect(result.httpMeta.response.status).toBe(200); expect(result.getFileDownloadResponse).toBeDefined(); expect( new Uint8Array(await streamToByteArray(result.getFileDownloadResponse)), ).toEqual(await filesToByteArray(".speakeasy/testfiles/example.file")); });