UNPKG

forge-apis

Version:

⚠️ Deprecated: This package is no longer maintained. Use 'https://github.com/autodesk-platform-services/aps-sdk-node' instead.

817 lines (723 loc) 26.6 kB
/** * Forge SDK * The Forge Platform contains an expanding collection of web service components that can be used with Autodesk cloud-based products or your own technologies. Take advantage of Autodesk’s expertise in design and engineering. * * Contact: forge.help@autodesk.com * * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /*jshint esversion: 9 */ module.export = (function () { 'use strict'; const expect = require('expect.js'); const sinon = require('sinon'); const ForgeSdk = require('../../src'); const ApiClient = require('../../src/ApiClient'); const BucketObjects = require('../../src/model/BucketObjects'); const ObjectDetails = require('../../src/model/ObjectDetails'); const ObjectFullDetails = require('../../src/model/ObjectFullDetails'); const ObjectS3Download = require('../../src/model/ObjectS3Download'); const ObjectS3Upload = require('../../src/model/ObjectS3Upload'); const ObjectCompleteS3Upload = require('../../src/model/ObjectCompleteS3Upload'); const PostBucketsSigned = require('../../src/model/PostBucketsSigned'); const PostObjectSigned = require('../../src/model/PostObjectSigned'); const Reason = require('../../src/model/Reason'); const Result = require('../../src/model/Result'); let instance; let oauth2client; let credentials; let mockedApiClientRequest; const sampleStrParam = 'test_string'; const sampleIntParam = 10; const APS_CLIENT_ID = process.env.APS_CLIENT_ID || '<your forge client ID>'; const APS_CLIENT_SECRET = process.env.APS_CLIENT_SECRET || '<your forge client secret>'; const apiClient = new ApiClient(); apiClient.defaultHeaders = { 'x-ads-test': sampleStrParam }; before(function () { oauth2client = new ForgeSdk.AuthClientTwoLegged(APS_CLIENT_ID, APS_CLIENT_SECRET, ['data:read', 'data:write']); credentials = { access_token: 'abce' }; instance = new ForgeSdk.ObjectsApi(apiClient); mockedApiClientRequest = sinon.stub(instance.apiClient, 'callApi'); }); after(function () { apiClient.callApi.restore(); }); describe('ObjectsApi', function () { describe('uploadObject', function () { it('should call uploadObject successfully', function (done) { const opts = { contentDisposition: 'application/octet-stream', ifMatch: sampleStrParam, xAdsContentSha1: sampleStrParam, }; const postBody = sampleStrParam; const pathParams = { bucketKey: sampleStrParam, objectKey: sampleStrParam }; const queryParams = {}; const headerParams = { 'Content-Length': sampleIntParam, 'Content-Disposition': opts.contentDisposition, 'If-Match': opts.ifMatch, 'x-ads-content-sha1': opts.xAdsContentSha1, }; const formParams = {}; const contentTypes = ['application/octet-stream']; const accepts = ['application/vnd.api+json', 'application/json']; const returnType = ObjectDetails; mockedApiClientRequest.withArgs('/oss/v2/buckets/{bucketKey}/objects/{objectKey}', 'PUT', pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType, oauth2client, credentials ).returns(Promise.resolve('Success result')); instance.uploadObject(sampleStrParam, sampleStrParam, sampleIntParam, sampleStrParam, opts, oauth2client, credentials) .then(function (response) { expect(response).to.be.ok(); done(); }, function (err) { done(err); }); }); }); describe('uploadChunk', function () { it('should call uploadChunk successfully', function (done) { const opts = { contentDisposition: 'application/octet-stream', contentType: 'application/octet-stream', xAdsChunkSha1: sampleStrParam, }; const postBody = sampleStrParam; const pathParams = { bucketKey: sampleStrParam, objectKey: sampleStrParam }; const queryParams = {}; const headerParams = { 'Content-Length': sampleIntParam, 'Content-Range': sampleStrParam, 'Content-Disposition': opts.contentDisposition, 'x-ads-chunk-sha1': opts.xAdsChunkSha1, 'Session-Id': sampleStrParam }; const formParams = {}; const contentTypes = opts.contentType || ['application/octet-stream']; const accepts = ['application/vnd.api+json', 'application/json']; const returnType = ObjectDetails; mockedApiClientRequest.withArgs('/oss/v2/buckets/{bucketKey}/objects/{objectKey}/resumable', 'PUT', pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType, oauth2client, credentials ).returns(Promise.resolve('Success result')); instance.uploadChunk(sampleStrParam, sampleStrParam, sampleIntParam, sampleStrParam, sampleStrParam, sampleStrParam, opts, oauth2client, credentials) .then(function (response) { expect(response).to.be.ok(); done(); }, function (err) { done(err); }); }); }); describe('getStatusBySessionId', function () { it('should call getStatusBySessionId successfully', function (done) { const postBody = null; const pathParams = { bucketKey: sampleStrParam, objectKey: sampleStrParam, sessionId: sampleStrParam }; const queryParams = {}; const headerParams = {}; const formParams = {}; const contentTypes = ['application/json']; const accepts = ['application/vnd.api+json', 'application/json']; const returnType = null; mockedApiClientRequest.withArgs('/oss/v2/buckets/{bucketKey}/objects/{objectKey}/status/{sessionId}', 'GET', pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType, oauth2client, credentials ).returns(Promise.resolve('Success result')); instance.getStatusBySessionId(sampleStrParam, sampleStrParam, sampleStrParam, oauth2client, credentials) .then(function (response) { expect(response).to.be.ok(); done(); }, function (err) { done(err); }); }); }); describe('getObjects', function () { it('should call getObjects successfully', function (done) { const opts = {}; const postBody = null; const pathParams = { bucketKey: sampleStrParam, }; const queryParams = { limit: opts.limit, beginsWith: opts.beginsWith, startAt: opts.startAt, }; const headerParams = {}; const formParams = {}; const contentTypes = ['application/json']; const accepts = ['application/vnd.api+json', 'application/json']; const returnType = BucketObjects; mockedApiClientRequest.withArgs('/oss/v2/buckets/{bucketKey}/objects', 'GET', pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType, oauth2client, credentials ).returns(Promise.resolve('Success result')); instance.getObjects(sampleStrParam, opts, oauth2client, credentials) .then(function (response) { expect(response).to.be.ok(); done(); }, function (err) { done(err); }); }); }); describe('getObjectDetails', function () { it('should call getObjectDetails successfully', function (done) { const opts = {}; const postBody = null; const pathParams = { bucketKey: sampleStrParam, objectKey: sampleStrParam, }; const queryParams = { with: opts.with, }; const headerParams = { 'If-Modified-Since': opts.ifModifiedSince, }; const formParams = {}; const contentTypes = ['application/json']; const accepts = ['application/vnd.api+json', 'application/json']; const returnType = ObjectFullDetails; mockedApiClientRequest.withArgs('/oss/v2/buckets/{bucketKey}/objects/{objectKey}/details', 'GET', pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType, oauth2client, credentials ).returns(Promise.resolve('Success result')); instance.getObjectDetails(sampleStrParam, sampleStrParam, opts, oauth2client, credentials) .then(function (response) { expect(response).to.be.ok(); done(); }, function (err) { done(err); }); }); }); describe('getObject', function () { it('should call getObject successfully', function (done) { const opts = {}; const postBody = null; const pathParams = { bucketKey: sampleStrParam, objectKey: sampleStrParam, }; const queryParams = {}; const headerParams = { Range: opts.range, 'If-None-Match': opts.ifNoneMatch, 'If-Modified-Since': opts.ifModifiedSince, 'Accept-Encoding': opts.acceptEncoding, }; const formParams = {}; const contentTypes = ['application/json']; const accepts = ['application/octet-stream']; const returnType = Object; mockedApiClientRequest.withArgs('/oss/v2/buckets/{bucketKey}/objects/{objectKey}', 'GET', pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType, oauth2client, credentials ).returns(Promise.resolve('Success result')); instance.getObject(sampleStrParam, sampleStrParam, opts, oauth2client, credentials) .then(function (response) { expect(response).to.be.ok(); done(); }, function (err) { done(err); }); }); }); describe('createSignedResource', function () { it('should call createSignedResource successfully', function (done) { const opts = { access: 'read', useCdn: true, }; const postBody = {}; const pathParams = { bucketKey: sampleStrParam, objectKey: sampleStrParam, }; const queryParams = { access: opts.access, useCdn: opts.useCdn, }; const headerParams = {}; const formParams = {}; const contentTypes = ['application/json']; const accepts = ['application/vnd.api+json', 'application/json']; const returnType = PostObjectSigned; mockedApiClientRequest.withArgs('/oss/v2/buckets/{bucketKey}/objects/{objectKey}/signed', 'POST', pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType, oauth2client, credentials ).returns(Promise.resolve('Success result')); instance.createSignedResource(pathParams.bucketKey, pathParams.objectKey, postBody, opts, oauth2client, credentials) .then(function (response) { expect(response).to.be.ok(); done(); }, function (err) { done(err); }); }); }); describe('uploadSignedResource', function () { it('should call uploadSignedResource successfully', function (done) { const opts = { contentLength: sampleIntParam, contentDisposition: 'application/octet-stream', xAdsRegion: 'US', ifMatch: sampleStrParam, xAdsContentSha1: sampleStrParam }; const postBody = sampleStrParam; const pathParams = { 'id': sampleStrParam }; const queryParams = {}; const headerParams = { 'Content-Length': opts.contentLength, 'Content-Disposition': opts.contentDisposition, 'x-ads-region': opts.xAdsRegion, 'If-Match': opts.ifMatch, 'x-ads-content-sha1': opts.xAdsContentSha1, }; const formParams = {}; const contentTypes = ['application/octet-stream']; const accepts = ['application/vnd.api+json', 'application/json']; const returnType = ObjectDetails; mockedApiClientRequest.withArgs('/oss/v2/signedresources/{id}', 'PUT', pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType, oauth2client, credentials ).returns(Promise.resolve('Success result')); instance.uploadSignedResource(pathParams.id, headerParams['Content-Length'], postBody, opts, oauth2client, credentials) .then(function (response) { expect(response).to.be.ok(); done(); }, function (err) { done(err); }); }); }); describe('uploadSignedResourcesChunk', function () { it('should call uploadSignedResourcesChunk successfully', function (done) { const opts = { contentRange: sampleStrParam, xAdsRegion: 'US', contentDisposition: 'application/octet-stream', ifMatch: sampleStrParam, xAdsChunkSha1: sampleStrParam, }; const postBody = sampleStrParam; const pathParams = { id: sampleStrParam, }; const queryParams = {}; const headerParams = { 'Content-Range': opts.contentRange, 'Content-Disposition': opts.contentDisposition, 'x-ads-region': opts.xAdsRegion, 'x-ads-chunk-sha1': opts.xAdsChunkSha1, 'Session-Id': sampleStrParam, }; const formParams = {}; const contentTypes = ['application/octet-stream']; const accepts = ['application/vnd.api+json', 'application/json']; const returnType = ObjectDetails; mockedApiClientRequest.withArgs('/oss/v2/signedresources/{id}/resumable', 'PUT', pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType, oauth2client, credentials ).returns(Promise.resolve('Success result')); instance.uploadSignedResourcesChunk(pathParams.id, opts.contentRange, headerParams['Session-Id'], postBody, opts, oauth2client, credentials) .then(function (response) { expect(response).to.be.ok(); done(); }, function (err) { done(err); }); }); }); describe('getSignedResource', function () { it('should call getSignedResource successfully', function (done) { const opts = { region: 'US', range: sampleStrParam, ifNoneMatch: sampleStrParam, ifModifiedSince: sampleStrParam, acceptEncoding: sampleStrParam }; const postBody = null; const pathParams = { id: sampleStrParam, }; const queryParams = { region: opts.region, }; const headerParams = { Range: opts.range, 'If-None-Match': opts.ifNoneMatch, 'If-Modified-Since': opts.ifModifiedSince, 'Accept-Encoding': opts.acceptEncoding, }; const formParams = {}; const contentTypes = ['application/json']; const accepts = ['application/octet-stream']; const returnType = Object; mockedApiClientRequest.withArgs('/oss/v2/signedresources/{id}', 'GET', pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType, oauth2client, credentials ).returns(Promise.resolve('Success result')); instance.getSignedResource(sampleStrParam, opts, oauth2client, credentials) .then(function (response) { expect(response).to.be.ok(); done(); }, function (err) { done(err); }); }); }); describe('deleteObject', function () { it('should call deleteObject successfully', function (done) { const postBody = null; const pathParams = { bucketKey: sampleStrParam, objectKey: sampleStrParam, }; const queryParams = {}; const headerParams = {}; const formParams = {}; const contentTypes = ['application/json']; const accepts = []; const returnType = null; mockedApiClientRequest.withArgs('/oss/v2/buckets/{bucketKey}/objects/{objectKey}', 'DELETE', pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType, oauth2client, credentials ).returns(Promise.resolve('Success result')); instance.deleteObject(sampleStrParam, sampleStrParam, oauth2client, credentials) .then(function (response) { expect(response).to.be.ok(); done(); }, function (err) { done(err); }); }); }); describe('copyTo', function () { it('should call copyTo successfully', function (done) { const postBody = null; const pathParams = { bucketKey: sampleStrParam, objectKey: sampleStrParam, newObjectKey: sampleStrParam, }; const queryParams = {}; const headerParams = {}; const formParams = {}; const contentTypes = ['application/json']; const accepts = ['application/vnd.api+json', 'application/json']; const returnType = ObjectDetails; mockedApiClientRequest.withArgs('/oss/v2/buckets/{bucketKey}/objects/{objectKey}/copyto/{newObjectKey}', 'PUT', pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType, oauth2client, credentials ).returns(Promise.resolve('Success result')); instance.copyTo(pathParams.bucketKey, pathParams.objectKey, pathParams.newObjectKey, oauth2client, credentials) .then(function (response) { expect(response).to.be.ok(); done(); }, function (err) { done(err); }); }); }); describe('deleteSignedResource', function () { it('should call deleteSignedResource successfully', function (done) { const opts = { region: 'US' }; const postBody = null; const pathParams = { id: sampleStrParam, }; const queryParams = { region: opts.region, }; const headerParams = {}; const formParams = {}; const contentTypes = ['application/json']; const accepts = ['text/plain']; const returnType = null; mockedApiClientRequest.withArgs('/oss/v2/signedresources/{id}', 'DELETE', pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType, oauth2client, credentials ).returns(Promise.resolve('Success result')); instance.deleteSignedResource(sampleStrParam, opts, oauth2client, credentials) .then(function (response) { expect(response).to.be.ok(); done(); }, function (err) { done(err); }); }); }); // S3 direct access describe('getS3DownloadURL', function () { it('should call getS3DownloadURL successfully', function (done) { const opts = { responseContentType: sampleStrParam, responseContentDisposition: sampleStrParam, responseCacheControl: sampleStrParam, publicResourceFallback: sampleStrParam, useCdn: true, minutesExpiration: sampleIntParam, ifNoneMatch: sampleStrParam, ifModifiedSince: sampleStrParam, }; const postBody = null; const pathParams = { bucketKey: sampleStrParam, objectKey: sampleStrParam, }; const queryParams = { 'response-content-type': opts.responseContentType, 'response-content-disposition': opts.responseContentDisposition, 'response-cache-control': opts.responseCacheControl, 'public-resource-fallback': opts.publicResourceFallback, useCdn: opts.useCdn, minutesExpiration: opts.minutesExpiration, }; const headerParams = { 'If-None-Match': opts.ifNoneMatch, 'If-Modified-Since': opts.ifModifiedSince, }; const formParams = {}; const contentTypes = ['application/json']; const accepts = ['application/vnd.api+json', 'application/json']; const returnType = ObjectS3Download; mockedApiClientRequest.withArgs('/oss/v2/buckets/{bucketKey}/objects/{objectKey}/signeds3download', 'GET', pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType, oauth2client, credentials ).returns(Promise.resolve('Success result')); instance.getS3DownloadURL(sampleStrParam, sampleStrParam, opts, oauth2client, credentials) .then(function (response) { expect(response).to.be.ok(); done(); }, function (err) { done(err); }); }); }); describe('getS3DownloadURLs', function () { it('should call getS3DownloadURLs successfully', function (done) { const opts = { useCdn: true, publicResourceFallback: sampleStrParam, minutesExpiration: sampleIntParam, }; const postBody = { requests: [ { objectKey: sampleStrParam, }, ], }; const pathParams = { bucketKey: sampleStrParam, }; const queryParams = { useCdn: opts.useCdn, 'public-resource-fallback': opts.publicResourceFallback, minutesExpiration: opts.minutesExpiration, }; const headerParams = {}; const formParams = {}; const contentTypes = ['application/json']; const accepts = ['application/vnd.api+json', 'application/json']; const returnType = Object; mockedApiClientRequest.withArgs('/oss/v2/buckets/{bucketKey}/objects/batchsigneds3download', 'POST', pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType, oauth2client, credentials ).returns(Promise.resolve('Success result')); instance.getS3DownloadURLs(pathParams.bucketKey, postBody, opts, oauth2client, credentials) .then(function (response) { expect(response).to.be.ok(); done(); }, function (err) { done(err); }); }); }); describe('getS3UploadURL', function () { it('should call getS3UploadURL successfully', function (done) { const opts = { uploadKey: sampleStrParam, firstPart: sampleIntParam, parts: sampleIntParam, useAcceleration: true, minutesExpiration: sampleIntParam, }; const postBody = null; const pathParams = { bucketKey: sampleStrParam, objectKey: sampleStrParam, }; const queryParams = { uploadKey: opts.uploadKey, firstPart: opts.firstPart, parts: opts.parts, useAcceleration: opts.useAcceleration, minutesExpiration: opts.minutesExpiration, }; const headerParams = {}; const formParams = {}; const contentTypes = ['application/json']; const accepts = ['application/vnd.api+json', 'application/json']; const returnType = Object; mockedApiClientRequest.withArgs('/oss/v2/buckets/{bucketKey}/objects/{objectKey}/signeds3upload', 'GET', pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType, oauth2client, credentials ).returns(Promise.resolve('Success result')); instance.getS3UploadURL(pathParams.bucketKey, pathParams.objectKey, opts, oauth2client, credentials) .then(function (response) { expect(response).to.be.ok(); done(); }, function (err) { done(err); }); }); }); describe('completeS3Upload', function () { it('should call completeS3Upload successfully', function (done) { const opts = { useCdn: true, xAdsMetaContentType: sampleStrParam, xAdsMetaContentDisposition: sampleStrParam, xAdsMetaContentEncoding: sampleStrParam, xAdsMetaCacheControl: sampleStrParam, }; const postBody = { uploadKey: sampleStrParam, eTags: [sampleStrParam], size: 1024, }; const pathParams = { bucketKey: sampleStrParam, objectKey: sampleStrParam, }; const queryParams = { useCdn: opts.useCdn, }; const headerParams = { 'x-ads-meta-Content-Type': opts.xAdsMetaContentType, 'x-ads-meta-Content-Disposition': opts.xAdsMetaContentDisposition, 'x-ads-meta-Content-Encoding': opts.xAdsMetaContentEncoding, 'x-ads-meta-Cache-Control': opts.xAdsMetaCacheControl, }; const formParams = {}; const contentTypes = ['application/json']; const accepts = ['application/vnd.api+json', 'application/json']; const returnType = ObjectCompleteS3Upload; mockedApiClientRequest.withArgs('/oss/v2/buckets/{bucketKey}/objects/{objectKey}/signeds3upload', 'POST', pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType, oauth2client, credentials ).returns(Promise.resolve('Success result')); instance.completeS3Upload(pathParams.bucketKey, pathParams.objectKey, postBody, opts, oauth2client, credentials) .then(function (response) { expect(response).to.be.ok(); done(); }, function (err) { done(err); }); }); }); describe('completeS3Uploads', function () { it('should call completeS3Uploads successfully', function (done) { const opts = { }; const postBody = { requests: [{ objectKey: sampleStrParam, uploadKey: sampleStrParam, }], }; const pathParams = { bucketKey: sampleStrParam, }; const queryParams = {}; const headerParams = {}; const formParams = {}; const contentTypes = ['application/json']; const accepts = ['application/vnd.api+json', 'application/json']; const returnType = Object; mockedApiClientRequest.withArgs('/oss/v2/buckets/{bucketKey}/objects/batchcompleteupload', 'POST', pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType, oauth2client, credentials ).returns(Promise.resolve('Success result')); instance.completeS3Uploads(pathParams.bucketKey, postBody, opts, oauth2client, credentials) .then(function (response) { expect(response).to.be.ok(); done(); }, function (err) { done(err); }); }); }); describe('getS3UploadURLs', function () { it('should call getS3UploadURLs successfully', function (done) { const opts = { useAcceleration: true, minutesExpiration: sampleIntParam, }; const postBody = { requests: [ { objectKey: sampleStrParam, }, ], }; const pathParams = { bucketKey: sampleStrParam, }; const queryParams = { useAcceleration: opts.useAcceleration, minutesExpiration: opts.minutesExpiration, }; const headerParams = {}; const formParams = {}; const contentTypes = ['application/json']; const accepts = ['application/vnd.api+json', 'application/json']; const returnType = Object; mockedApiClientRequest.withArgs('/oss/v2/buckets/{bucketKey}/objects/batchsigneds3upload', 'POST', pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType, oauth2client, credentials ).returns(Promise.resolve('Success result')); instance.getS3UploadURLs(pathParams.bucketKey, postBody, opts, oauth2client, credentials) .then(function (response) { expect(response).to.be.ok(); done(); }, function (err) { done(err); }); }); }); }); }());