Skip to content

Commit

Permalink
feat(editor-content): apply format #29872
Browse files Browse the repository at this point in the history
  • Loading branch information
nicobytes committed Sep 27, 2024
1 parent 6ffdd79 commit 274c6af
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ describe('DotUploadFileService', () => {
let spectator: SpectatorHttp<DotUploadFileService>;
let dotWorkflowActionsFireService: SpyObject<DotWorkflowActionsFireService>;


const createHttp = createHttpFactory({
service: DotUploadFileService,
providers: [DotUploadFileService, mockProvider(DotWorkflowActionsFireService)]
Expand All @@ -27,7 +26,9 @@ describe('DotUploadFileService', () => {

describe('uploadDotAsset', () => {
it('should upload a file as a dotAsset', () => {
dotWorkflowActionsFireService.newContentlet.mockReturnValueOnce(of({ entity: { identifier: 'test' } }));
dotWorkflowActionsFireService.newContentlet.mockReturnValueOnce(
of({ entity: { identifier: 'test' } })
);

const file = new File([''], 'test.png', {
type: 'image/png'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class DotUploadFileService {
readonly #BASE_URL = '/api/v1/workflow/actions/default';
readonly #httpClient = inject(HttpClient);
readonly #uploadService = inject(DotUploadService);
readonly #workflowActionsFireService = inject(DotWorkflowActionsFireService)
readonly #workflowActionsFireService = inject(DotWorkflowActionsFireService);

publishContent({
data,
Expand Down Expand Up @@ -95,6 +95,10 @@ export class DotUploadFileService {
const formData = new FormData();
formData.append('file', file);

return this.#workflowActionsFireService.newContentlet<DotCMSContentlet>('dotAsset', { file: file.name }, formData);
return this.#workflowActionsFireService.newContentlet<DotCMSContentlet>(
'dotAsset',
{ file: file.name },
formData
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ describe('DotWorkflowActionsFireService', () => {
const formData = new FormData();
formData.append('file', file);

spectator.service.newContentlet('dotAsset', { file: file.name }, formData).subscribe((res) => {
expect(res).toEqual([mockResult]);
done();
});
spectator.service
.newContentlet('dotAsset', { file: file.name }, formData)
.subscribe((res) => {
expect(res).toEqual([mockResult]);
done();
});

const req = spectator.expectOne(
'/api/v1/workflow/actions/default/fire/NEW',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ export class DotWorkflowActionsFireService {
*
* @memberof DotWorkflowActionsFireService
*/
newContentlet<T>(contentType: string, data: { [key: string]: string }, formData?: FormData): Observable<T> {
newContentlet<T>(
contentType: string,
data: { [key: string]: string },
formData?: FormData
): Observable<T> {
return this.request<T>({ contentType, data, action: ActionToFire.NEW, formData });
}

Expand Down Expand Up @@ -175,28 +179,25 @@ export class DotWorkflowActionsFireService {
individualPermissions,
formData
}: DotActionRequestOptions): Observable<T> {

let url = `${this.BASE_URL}/actions/default/fire/${action}`;

const contentlet = contentType ? { contentType: contentType, ...data } : data;
const bodyRequest = individualPermissions
? { contentlet, individualPermissions }
: { contentlet };
? { contentlet, individualPermissions }
: { contentlet };

if (data['inode']) {
url += `?inode=${data['inode']}`
url += `?inode=${data['inode']}`;
}

if (formData) {
formData.append('json', JSON.stringify(bodyRequest));
}

return this.httpClient
.put(
url,
formData ? formData : bodyRequest,
{ headers: formData ? new HttpHeaders() : this.defaultHeaders }
)
.put(url, formData ? formData : bodyRequest, {
headers: formData ? new HttpHeaders() : this.defaultHeaders
})
.pipe(take(1), pluck('entity'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface DotCMSContentlet {
url: string;
working: boolean;
body?: string;
content?: string;
contentTypeIcon?: string;
variant?: string;
__icon__?: string;
Expand Down

0 comments on commit 274c6af

Please sign in to comment.