Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should accept server settings', async () => {
const drive = new Drive({ serverSettings });
handleRequest(drive, 201, DEFAULT_DIR);
const options: Contents.ICreateOptions = {
path: '/foo',
type: 'file',
ext: 'txt'
};
const model = await drive.newUntitled(options);
expect(model.content[0].path).to.equal(DEFAULT_DIR.content[0].path);
});
it('should encode characters', async () => {
const drive = new Drive({ serverSettings: settings });
const url = await drive.getDownloadUrl('b ar?3.txt');
expect(url).to.equal('http://foo/files/b%20ar%3F3.txt');
});
it('should be emitted when a file changes', async () => {
const drive = new Drive();
handleRequest(drive, 201, DEFAULT_FILE);
let called = false;
drive.fileChanged.connect((sender, args) => {
expect(sender).to.equal(drive);
expect(args.type).to.equal('new');
expect(args.oldValue).to.be.null;
expect(args.newValue.path).to.equal(DEFAULT_FILE.path);
called = true;
});
await drive.newUntitled();
expect(called).to.equal(true);
});
});
it('should accept options', () => {
const contents = new ContentsManager({
defaultDrive: new Drive()
});
expect(contents).to.be.an.instanceof(ContentsManager);
});
});
it('should fail for an incorrect model', async () => {
const drive = new Drive();
const cp = JSON.parse(JSON.stringify(DEFAULT_CP));
delete cp.last_modified;
handleRequest(drive, 201, cp);
const checkpoint = drive.createCheckpoint('/foo/bar.txt');
await expectFailure(checkpoint);
});
it('should leave alone names with ":" that are not drive names', () => {
contents.addDrive(new Drive({ name: 'other' }));
expect(
contents.driveName('which:foo/odd:directory/example:file.txt')
).to.equal('');
});
});
it('should encode characters', async () => {
const drive = new Drive({ serverSettings: settings });
const contents = new ContentsManager({ defaultDrive: drive });
const url = await contents.getDownloadUrl('b ar?3.txt');
expect(url).to.equal('http://foo/files/b%20ar%3F3.txt');
});
it('should create a directory', async () => {
const drive = new Drive();
handleRequest(drive, 201, DEFAULT_DIR);
const options: Contents.ICreateOptions = {
path: '/foo',
type: 'directory'
};
const newDir = drive.newUntitled(options);
const model = await newDir;
expect(model.content[0].path).to.equal(DEFAULT_DIR.content[0].path);
});
it('should emit the fileChanged signal', async () => {
const drive = new Drive();
handleRequest(drive, 201, DEFAULT_FILE);
let called = false;
drive.fileChanged.connect((sender, args) => {
expect(args.type).to.equal('new');
expect(args.oldValue).to.be.null;
expect(args.newValue.path).to.equal(DEFAULT_FILE.path);
called = true;
});
await drive.copy('/foo/bar.txt', '/baz');
expect(called).to.equal(true);
});
it('should create a new file', async () => {
const drive = new Drive();
handleRequest(drive, 201, DEFAULT_FILE);
const save = drive.save('/foo', { type: 'file', name: 'test' });
const model = await save;
expect(model.created).to.equal(DEFAULT_FILE.created);
});