Skip to content

Commit

Permalink
unit test fixes for migration (#9217)
Browse files Browse the repository at this point in the history
* reenabled excluded test in TagNodeList

* fixed tests for UploadApi in js-api
  • Loading branch information
wojd0 authored and VitoAlbano committed Jun 15, 2024
1 parent 5b90085 commit bcb6d38
Showing 1 changed file with 35 additions and 37 deletions.
72 changes: 35 additions & 37 deletions lib/js-api/test/upload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@

import assert from 'assert';
import { EcmAuthMock, UploadMock } from './mockObjects';
import fs from 'fs';
import { UploadApi, AlfrescoApi, NodeEntry } from '../src';
import { createReadStream } from 'fs';
import { join } from 'path';
import { UploadApi, AlfrescoApi } from '../src';

// eslint-disable-next-line ban/ban
xdescribe('Upload', () => {
describe('Upload', () => {
let authResponseMock: EcmAuthMock;
let uploadMock: UploadMock;
let alfrescoJsApi: AlfrescoApi;
let uploadApi: UploadApi;

const createTestFileStream = (fileName: string) => createReadStream(join(__dirname, 'mockObjects/assets', fileName));

beforeEach(async () => {
const hostEcm = 'https://127.0.0.1:8080';

Expand All @@ -44,46 +46,42 @@ xdescribe('Upload', () => {
});

describe('Upload File', () => {
it('upload file should return 200 if is all ok', (done) => {
it('upload file should return 200 if is all ok', async () => {
uploadMock.get201CreationFile();

const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
const file = createTestFileStream('testFile.txt');

uploadApi.uploadFile(file).then((data: NodeEntry) => {
assert.equal(data.entry.isFile, true);
assert.equal(data.entry.name, 'testFile.txt');
done();
});
const data = await uploadApi.uploadFile(file);
assert.equal(data.entry.isFile, true);
assert.equal(data.entry.name, 'testFile.txt');
});

it('upload file should get 409 if new name clashes with an existing file in the current parent folder', (done) => {
uploadMock.get409CreationFileNewNameClashes();

const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
const file = createTestFileStream('testFile.txt');

uploadApi.uploadFile(file).then(
() => {},
uploadApi.uploadFile(file).catch(
(error: any) => {
assert.equal(error.status, 409);
done();
}
);
});

it('upload file should get 200 and rename if the new name clashes with an existing file in the current parent folder and autorename is true', (done) => {
it('upload file should get 200 and rename if the new name clashes with an existing file in the current parent folder and autorename is true', async () => {
uploadMock.get201CreationFileAutoRename();

const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
const file = createTestFileStream('testFile.txt');

uploadApi.uploadFile(file, null, null, null, { autoRename: true }).then((data: NodeEntry) => {
assert.equal(data.entry.isFile, true);
assert.equal(data.entry.name, 'testFile-2.txt');
done();
});
const data = await uploadApi.uploadFile(file, null, null, null, { autoRename: true });

assert.equal(data.entry.isFile, true);
assert.equal(data.entry.name, 'testFile-2.txt');
});

it('Abort should stop the file file upload', (done) => {
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
const file = createTestFileStream('testFile.txt');

const promise: any = uploadApi.uploadFile(file, null, null, null, { autoRename: true });
promise.once('abort', () => {
Expand All @@ -98,7 +96,7 @@ xdescribe('Upload', () => {
it('Upload should fire done event at the end of an upload', (done) => {
uploadMock.get201CreationFile();

const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
const file = createTestFileStream('testFile.txt');

const uploadPromise: any = uploadApi.uploadFile(file);

Expand All @@ -111,7 +109,7 @@ xdescribe('Upload', () => {
it('Upload should fire error event if something go wrong', (done) => {
uploadMock.get409CreationFileNewNameClashes();

const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
const file = createTestFileStream('testFile.txt');

const uploadPromise: any = uploadApi.uploadFile(file);
uploadPromise.catch(() => {});
Expand All @@ -123,7 +121,7 @@ xdescribe('Upload', () => {
it('Upload should fire unauthorized event if get 401', (done) => {
uploadMock.get401Response();

const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
const file = createTestFileStream('testFile.txt');

const uploadPromise: any = uploadApi.uploadFile(file);

Expand All @@ -136,15 +134,15 @@ xdescribe('Upload', () => {
it('Upload should fire progress event during the upload', (done) => {
uploadMock.get201CreationFile();

const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
const file = createTestFileStream('testFile.txt');
const uploadPromise: any = uploadApi.uploadFile(file);

uploadPromise.once('progress', () => done());
});

it('Multiple Upload should fire progress events on the right promise during the upload', (done) => {
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
const fileTwo = fs.createReadStream('./test/mockObjects/assets/testFile2.txt');
const file = createTestFileStream('testFile.txt');
const fileTwo = createTestFileStream('testFile2.txt');

let progressOneOk = false;
let progressTwoOk = false;
Expand Down Expand Up @@ -177,8 +175,8 @@ xdescribe('Upload', () => {
});

it('Multiple Upload should fire error events on the right promise during the upload', (done) => {
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
const fileTwo = fs.createReadStream('./test/mockObjects/assets/testFile2.txt');
const file = createTestFileStream('testFile.txt');
const fileTwo = createTestFileStream('testFile2.txt');

let errorOneOk = false;
let errorTwoOk = false;
Expand Down Expand Up @@ -213,8 +211,8 @@ xdescribe('Upload', () => {
});

it('Multiple Upload should fire success events on the right promise during the upload', (done) => {
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
const fileTwo = fs.createReadStream('./test/mockObjects/assets/testFile2.txt');
const file = createTestFileStream('testFile.txt');
const fileTwo = createTestFileStream('testFile2.txt');

let successOneOk = false;
let successTwoOk = false;
Expand Down Expand Up @@ -249,8 +247,8 @@ xdescribe('Upload', () => {
});

it('Multiple Upload should resolve the correct promise', (done) => {
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
const fileTwo = fs.createReadStream('./test/mockObjects/assets/testFile2.txt');
const file = createTestFileStream('testFile.txt');
const fileTwo = createTestFileStream('testFile2.txt');

let resolveOneOk = false;
let resolveTwoOk = false;
Expand All @@ -275,8 +273,8 @@ xdescribe('Upload', () => {
});

it('Multiple Upload should reject the correct promise', (done) => {
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
const fileTwo = fs.createReadStream('./test/mockObjects/assets/testFile2.txt');
const file = createTestFileStream('testFile.txt');
const fileTwo = createTestFileStream('testFile2.txt');

let rejectOneOk = false;
let rejectTwoOk = false;
Expand All @@ -301,7 +299,7 @@ xdescribe('Upload', () => {
});

it('Is possible use chain events', (done) => {
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
const file = createTestFileStream('testFile.txt');

uploadMock.get401Response();

Expand Down

0 comments on commit bcb6d38

Please sign in to comment.