Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unit test fixes for migration #9217

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ describe('TagNodeList', () => {
});
});

// eslint-disable-next-line
xdescribe('Limit tags display', () => {
describe('Limit tags display', () => {
let initialEntries: TagEntry[];

/**
Expand Down
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