Fix wpAttachmentsService spec

pull/4605/head
Oliver Günther 8 years ago
parent 8af6677dfa
commit a07e499373
  1. 21
      frontend/app/components/work-packages/wp-attachments/wp-attachments.service.test.ts
  2. 8
      frontend/app/components/work-packages/wp-attachments/wp-attachments.service.ts

@ -28,7 +28,7 @@
declare const WebKitBlobBuilder:any;
describe('wpAttachments', () => {
describe('wpAttachments service', () => {
var wpAttachments;
var $httpBackend;
@ -36,14 +36,7 @@ describe('wpAttachments', () => {
id: 1,
$isHal: true,
attachments: {
href: '/api/v3/work_packages/1/attachments',
},
$links: {
attachments:{
$link:{
href:'/api/v3/work_packages/1/attachments'
}
}
href: '/api/v3/work_packages/1/attachments',
}
};
@ -51,11 +44,7 @@ describe('wpAttachments', () => {
var attachment = {
id: 1,
_type: "Attachment",
_links: {
self: {
href: "/api/v3/attachments/1"
}
}
href: "/api/v3/attachments/1"
};
beforeEach(angular.mock.module('openproject.workPackages'));
@ -73,9 +62,7 @@ describe('wpAttachments', () => {
describe('loading attachments', () => {
beforeEach(() => {
$httpBackend.expectGET('/api/v3/work_packages/1/attachments').respond({
_embedded: {
elements: [1,2,3]
}
elements: [1,2,3]
});
});

@ -41,7 +41,7 @@ export class WpAttachmentsService {
}
public upload(workPackage:WorkPackageResourceInterface, files:File[]):ng.IPromise<any> {
const uploadPath:string = workPackage.$links.attachments.$link.href;
const uploadPath:string = workPackage.attachments.href;
const uploads = _.map(files, (file:File) => {
var options:Object = {
fields: {
@ -79,11 +79,11 @@ export class WpAttachmentsService {
reload:boolean = false):ng.IPromise<any[]> {
const loadedAttachments = this.$q.defer();
const path:string = workPackage.$links.attachments.$link.href;
const path:string = workPackage.attachments.href;
this.$http.get(path, {cache: !reload})
.success((response:any) => {
_.remove(this.attachments);
_.extend(this.attachments, response._embedded.elements);
_.extend(this.attachments, response.elements);
loadedAttachments.resolve(this.attachments);
})
.error(err => {
@ -95,7 +95,7 @@ export class WpAttachmentsService {
public remove(fileOrAttachment:any):void {
if (fileOrAttachment._type === 'Attachment') {
const path:string = fileOrAttachment._links.self.href;
const path:string = fileOrAttachment.href;
this.$http.delete(path)
.success(() => {

Loading…
Cancel
Save