Implement upload method for AttachmentCollectionResource

pull/4783/head
Alex Dik 8 years ago
parent e593fd954c
commit f061e29a05
  1. 41
      frontend/app/components/api/api-v3/hal-resources/attachment-collection-resource.service.test.ts
  2. 20
      frontend/app/components/api/api-v3/hal-resources/attachment-collection-resource.service.ts

@ -27,16 +27,51 @@
// ++
import {opApiModule, opServicesModule} from '../../../../angular-modules';
import {AttachmentCollectionResource} from './attachment-collection-resource.service';
import {OpenProjectFileUploadService} from '../../op-file-upload/op-file-upload.service';
import SinonStub = Sinon.SinonStub;
describe('AttachmentCollectionResource service', () => {
var AttachmentCollectionResource;
var opFileUpload: OpenProjectFileUploadService;
beforeEach(angular.mock.module(opApiModule.name, opServicesModule.name));
beforeEach(angular.mock.inject(function (_AttachmentCollectionResource_) {
[AttachmentCollectionResource] = _.toArray(arguments);
beforeEach(angular.mock.module(
opApiModule.name,
opServicesModule.name
));
beforeEach(angular.mock.inject(function (_AttachmentCollectionResource_,
_opFileUpload_) {
[
AttachmentCollectionResource,
opFileUpload
] = _.toArray(arguments);
}));
it('should exist', () => {
expect(AttachmentCollectionResource).to.exist;
});
describe('when creating an attachment collection', () => {
var collection: AttachmentCollectionResource;
beforeEach(() => {
collection = new AttachmentCollectionResource({
_links: {self: {href: 'attachments'}}
}, true);
});
describe('when uploading files', () => {
var files: any[] = [{}, {}];
var uploadStub: SinonStub;
beforeEach(() => {
uploadStub = sinon.stub(opFileUpload, 'upload');
collection.upload(files);
});
it('should call the `opFileUpload` service accordingly', () => {
expect(uploadStub.calledWith(collection.$href, files)).to.be.true;
});
});
});
});

@ -29,16 +29,32 @@
import {opApiModule} from '../../../../angular-modules';
import {CollectionResource} from './collection-resource.service';
import {HalResource} from './hal-resource.service';
import {
OpenProjectFileUploadService,
UploadFile
} from '../../op-file-upload/op-file-upload.service';
import IPromise = angular.IPromise;
var opFileUpload: OpenProjectFileUploadService;
export class AttachmentCollectionResource extends CollectionResource {
/**
* Upload the given files to the $href property of this resource.
*/
public upload(files: UploadFile[]): IPromise<any> {
return opFileUpload.upload(this.$href, files);
}
}
export interface AttachmentCollectionResourceInterface extends AttachmentCollectionResource {
elements:HalResource[];
elements: HalResource[];
}
function attachmentCollectionResourceService() {
function attachmentCollectionResourceService(...args) {
[opFileUpload] = args;
return AttachmentCollectionResource;
}
attachmentCollectionResourceService.$inject = ['opFileUpload'];
opApiModule.factory('AttachmentCollectionResource', attachmentCollectionResourceService);

Loading…
Cancel
Save