UNPKG

smc-hub

Version:

CoCalc: Backend webserver component

277 lines (269 loc) 8.47 kB
// Generated by CoffeeScript 2.5.1 (function() { //######################################################################## // This file is part of CoCalc: Copyright © 2020 Sagemath, Inc. // License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details //######################################################################## /* Testing API functions that copy from one project to another */ var api, expect, misc, setup, teardown; api = require('./apitest'); ({setup, teardown} = api); misc = require('smc-util/misc'); expect = require('expect'); describe('testing copy between projects -- ', function() { var content, path1, path2, path3, project_id, project_id2, src_dir; before(setup); after(teardown); project_id = void 0; project_id2 = void 0; path1 = 'doc1.txt'; path2 = 'B2/doc2.txt'; path3 = 'FOO/abc.txt'; content = 'TEST CONTENT'; src_dir = 'TEST_DIR'; it("creates source project", function(done) { return api.call({ event: 'create_project', body: { title: 'TEST1', description: 'Source Project' }, cb: function(err, resp) { expect(resp != null ? resp.event : void 0).toBe('project_created'); project_id = resp.project_id; return done(err); } }); }); it("creates target project", function(done) { return api.call({ event: 'create_project', body: { title: 'TEST2', description: 'Target Project' }, cb: function(err, resp) { expect(resp != null ? resp.event : void 0).toBe('project_created'); project_id2 = resp.project_id; return done(err); } }); }); it("creates file in source project", function(done) { this.timeout(25000); return api.call({ event: 'write_text_file_to_project', body: { project_id: project_id, content: content, path: path1 }, cb: function(err, resp) { expect(err).toEqual(null); expect(resp != null ? resp.event : void 0).toBe('file_written_to_project'); return done(err); } }); }); it("copies file to a private target", function(done) { this.timeout(25000); return api.call({ event: 'copy_path_between_projects', body: { src_project_id: project_id, src_path: path1, target_project_id: project_id2 }, cb: function(err, resp) { expect(err).toEqual(null); expect(resp != null ? resp.event : void 0).toBe('success'); return done(err); } }); }); it("reads target file 1", function(done) { this.timeout(25000); return api.call({ event: 'read_text_file_from_project', body: { project_id: project_id2, path: path1 }, cb: function(err, resp) { expect(err).toEqual(null); expect(resp != null ? resp.event : void 0).toBe('text_file_read_from_project'); expect(resp != null ? resp.content : void 0).toBe(content); return done(err); } }); }); it("creates folder with text file in source project", function(done) { this.timeout(25000); return api.call({ event: 'write_text_file_to_project', body: { project_id: project_id, content: content, path: path2 }, cb: function(err, resp) { expect(err).toEqual(null); expect(resp != null ? resp.event : void 0).toBe('file_written_to_project'); return done(err); } }); }); it("copies src with directory and file", function(done) { this.timeout(25000); return api.call({ event: 'copy_path_between_projects', body: { src_project_id: project_id, src_path: path2, target_project_id: project_id2 }, cb: function(err, resp) { expect(err).toEqual(null); expect(resp != null ? resp.event : void 0).toBe('success'); return done(err); } }); }); it("reads target file 2", function(done) { this.timeout(25000); return api.call({ event: 'read_text_file_from_project', body: { project_id: project_id2, path: path2 }, cb: function(err, resp) { expect(resp != null ? resp.event : void 0).toBe('text_file_read_from_project'); expect(resp != null ? resp.content : void 0).toBe(content); return done(err); } }); }); it("copies file to directory", function(done) { // src:'B2/doc2.txt' tgt:'DIR3/ result:'DIR3/doc2.txt' this.timeout(25000); return api.call({ event: 'copy_path_between_projects', body: { src_project_id: project_id, src_path: path2, target_project_id: project_id2, target_path: 'DIR3/' }, cb: function(err, resp) { expect(err).toEqual(null); expect(resp != null ? resp.event : void 0).toBe('success'); return done(err); } }); }); it("reads target file 3", function(done) { this.timeout(25000); return api.call({ event: 'read_text_file_from_project', body: { project_id: project_id2, path: 'DIR3/doc2.txt' }, cb: function(err, resp) { expect(err).toEqual(null); expect(resp != null ? resp.event : void 0).toBe('text_file_read_from_project'); expect(resp != null ? resp.content : void 0).toBe(content); return done(err); } }); }); it("copies directory to directory", function(done) { // src:'B2/' tgt:'DIR4/ result:'DIR4/doc2.txt' this.timeout(25000); return api.call({ event: 'copy_path_between_projects', body: { src_project_id: project_id, src_path: 'B2/', target_project_id: project_id2, target_path: 'DIR4/' }, cb: function(err, resp) { expect(err).toEqual(null); expect(resp != null ? resp.event : void 0).toBe('success'); return done(err); } }); }); it("reads target file 4", function(done) { this.timeout(25000); return api.call({ event: 'read_text_file_from_project', body: { project_id: project_id2, path: 'DIR4/doc2.txt' }, cb: function(err, resp) { expect(err).toEqual(null); expect(resp != null ? resp.event : void 0).toBe('text_file_read_from_project'); expect(resp != null ? resp.content : void 0).toBe(content); return done(err); } }); }); it("uses API query to make a file public", function(done) { return api.call({ event: 'query', body: { query: { public_paths: { project_id: project_id, path: path2, description: 'Doc #2' } } }, cb: function(err, resp) { expect(resp != null ? resp.event : void 0).toBe('query'); return done(err); } }); }); it("copies a public file to different target dir", function(done) { // src:'B2/doc2.txt'(public) tgt:'FOO/abc.txt' this.timeout(25000); return api.call({ event: 'copy_public_path_between_projects', body: { src_project_id: project_id, src_path: path2, target_project_id: project_id2, target_path: path3 }, cb: function(err, resp) { expect(resp != null ? resp.event : void 0).toBe('success'); return done(err); } }); }); return it("reads copied public file", function(done) { this.timeout(25000); return api.call({ event: 'read_text_file_from_project', body: { project_id: project_id2, path: path3 }, cb: function(err, resp) { expect(resp != null ? resp.event : void 0).toBe('text_file_read_from_project'); expect(resp != null ? resp.content : void 0).toBe(content); return done(err); } }); }); }); }).call(this); //# sourceMappingURL=copy_between_projects.js.map