CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/sync/table/test/client-test.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
/*
7
Minimal client class that we use for testing.
8
*/
9
10
import { EventEmitter } from "events";
11
import { bind_methods, keys } from "@cocalc/util/misc";
12
13
export class ClientTest extends EventEmitter {
14
private initial_get_query: any[];
15
public set_queries: any[] = [];
16
17
constructor(initial_get_query) {
18
super();
19
20
this.initial_get_query = initial_get_query;
21
bind_methods(this, ["query", "dbg", "query_cancel"]);
22
}
23
24
public is_project(): boolean {
25
return false;
26
}
27
28
public is_browser(): boolean {
29
return true;
30
}
31
32
public is_compute_server(): boolean {
33
return false;
34
}
35
36
public is_connected(): boolean {
37
return true;
38
}
39
40
public is_signed_in(): boolean {
41
return true;
42
}
43
44
public dbg(_: string): Function {
45
return console.log;
46
}
47
48
public query(opts): void {
49
if (opts.options && opts.options.length === 1 && opts.options[0].set) {
50
// set query
51
this.set_queries.push(opts);
52
opts.cb();
53
} else {
54
// get query -- returns predetermined result
55
const table = keys(opts.query)[0];
56
opts.cb(undefined, { query: { [table]: this.initial_get_query } });
57
}
58
}
59
60
public query_cancel(_): void {}
61
62
public alert_message(_): void {}
63
64
public server_time(): Date {
65
return new Date();
66
}
67
68
public touch_project(_): void {}
69
70
is_deleted = (_path: string, _project_id: string) => {
71
// not implemented yet in general
72
return undefined;
73
};
74
}
75
76