You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.2 KiB
75 lines
2.2 KiB
/**
|
|
* Created by Julin on 2021/03/24.
|
|
*/
|
|
'use strict';
|
|
|
|
const expect = require('chai').expect;
|
|
const path = require('path');
|
|
|
|
const Attachment = require('../lib/mw');
|
|
const opts = require('./config')({
|
|
rootPath: 'anxinyun',
|
|
childPath: 'file-center',
|
|
uploadPath: 'reports'
|
|
});
|
|
|
|
describe('attachment', function () {
|
|
this.timeout(10000);
|
|
|
|
let attachment, srcFile;
|
|
|
|
before(async () => {
|
|
attachment = new Attachment(opts);
|
|
srcFile = path.posix.join(__dirname, 'files', 'test-文档1.txt');
|
|
});
|
|
|
|
after(async () => {
|
|
// do something...
|
|
});
|
|
|
|
it('upload file to local server(assign path without segments) successfully', function (done) {
|
|
(async function () {
|
|
try {
|
|
let rslt = await attachment.upload(srcFile);
|
|
expect(rslt).to.be.an('object').that.has.all.keys('key', 'url');
|
|
expect(rslt.key).to.be.a('string');
|
|
done();
|
|
} catch (err) {
|
|
done(err);
|
|
}
|
|
})()
|
|
})
|
|
|
|
it('upload file to local server(assign path without segments) successfully', function (done) {
|
|
(async function () {
|
|
try {
|
|
let conf = require('./config')();
|
|
let svc = new Attachment(conf);
|
|
let rslt = await svc.upload(srcFile);
|
|
expect(rslt).to.be.an('object').that.has.all.keys('key', 'url');
|
|
expect(rslt.key).to.be.a('string');
|
|
done();
|
|
} catch (err) {
|
|
done(err);
|
|
}
|
|
})()
|
|
})
|
|
|
|
it('upload file to local server(assign full directory path) successfully', function (done) {
|
|
(async function () {
|
|
try {
|
|
let conf = require('./config')({
|
|
rootPath: 'E:',
|
|
childPath: 'attachement-test'
|
|
});
|
|
let svc = new Attachment(conf);
|
|
let rslt = await svc.upload(srcFile, { uploadPath: 'assets' });
|
|
expect(rslt).to.be.an('object').that.has.all.keys('key', 'url');
|
|
expect(rslt.key).to.be.a('string');
|
|
done();
|
|
} catch (err) {
|
|
done(err);
|
|
}
|
|
})()
|
|
})
|
|
});
|
|
|