|
1 | 1 | import sinon from 'sinon';
|
2 |
| -const events = require('events'); |
3 | 2 |
|
4 |
| -const subscribeMock = jest.fn(() => ({ |
5 |
| - ready: jest.fn(() => true), |
6 |
| - stop: sinon.stub(), |
7 |
| -})); |
8 |
| -const callMock = sinon.stub(); |
9 |
| -const applyMock = sinon.stub(); |
10 |
| - |
11 |
| -class MockLocalStorage { |
12 |
| - store: {}; |
13 |
| - constructor() { |
14 |
| - this.store = {}; |
15 |
| - } |
16 |
| - |
17 |
| - getItem(key) { |
18 |
| - return this.store[key] || null; |
19 |
| - } |
20 |
| - |
21 |
| - setItem(key, value) { |
22 |
| - this.store[key] = String(value); |
23 |
| - } |
24 |
| - |
25 |
| - removeItem(key) { |
26 |
| - delete this.store[key]; |
27 |
| - } |
28 |
| - |
29 |
| - clear() { |
30 |
| - this.store = {}; |
31 |
| - } |
32 |
| -} |
33 |
| - |
34 |
| -module.exports = { |
35 |
| - Meteor: { |
36 |
| - loginWithSamlToken: sinon.stub(), |
37 |
| - subscribe: subscribeMock, |
38 |
| - call: callMock, |
39 |
| - apply: applyMock, |
40 |
| - methods: sinon.stub(), |
41 |
| - connection: { |
42 |
| - subscribe: subscribeMock, |
43 |
| - call: callMock, |
44 |
| - apply: applyMock, |
45 |
| - status: sinon.stub(() => ({ connected: true })), |
46 |
| - reconnect: sinon.stub(), |
47 |
| - disconnect: sinon.stub(), |
48 |
| - _stream: new events.EventEmitter(), |
49 |
| - }, |
50 |
| - isClient: true, |
51 |
| - isServer: false, |
52 |
| - _localStorage: new MockLocalStorage(), |
53 |
| - }, |
54 |
| - Mongo: { |
55 |
| - Collection: class Collection { |
56 |
| - name: any; |
57 |
| - find: sinon.SinonStub<any[], any>; |
58 |
| - findOne: sinon.SinonStub<any[], any>; |
59 |
| - insert: sinon.SinonStub<any[], any>; |
60 |
| - update: sinon.SinonStub<any[], any>; |
61 |
| - remove: sinon.SinonStub<any[], any>; |
62 |
| - constructor(name) { |
63 |
| - this.name = name; |
64 |
| - this.find = sinon.stub().returns({ |
65 |
| - fetch: () => [{ _id: '1', name: 'Document' }], |
66 |
| - count: () => 1, |
67 |
| - observe: sinon.stub(), |
68 |
| - }); |
69 |
| - this.findOne = sinon.stub().returns({ _id: '1', name: 'Document' }); |
70 |
| - this.insert = sinon.stub(); |
71 |
| - this.update = sinon.stub(); |
72 |
| - this.remove = sinon.stub(); |
73 |
| - } |
74 |
| - }, |
75 |
| - }, |
76 |
| - Accounts: { |
77 |
| - createUser: sinon.stub(), |
78 |
| - findUserByEmail: sinon.stub(), |
79 |
| - findUserByUsername: sinon.stub(), |
80 |
| - validateLoginAttempt: sinon.stub(), |
81 |
| - onLogin: sinon.stub(), |
82 |
| - onLoginFailure: sinon.stub(), |
83 |
| - }, |
84 |
| - check: sinon.stub(), |
85 |
| - Match: { |
86 |
| - Maybe: sinon.stub(), |
87 |
| - OneOf: sinon.stub(), |
88 |
| - ObjectIncluding: sinon.stub(), |
89 |
| - Where: sinon.stub(), |
90 |
| - }, |
91 |
| - Tracker: { |
92 |
| - autorun: sinon.stub(), |
93 |
| - nonreactive: sinon.stub(), |
94 |
| - Dependency: class { |
95 |
| - depend: sinon.SinonStub<any[], any>; |
96 |
| - changed: sinon.SinonStub<any[], any>; |
97 |
| - constructor() { |
98 |
| - this.depend = sinon.stub(); |
99 |
| - this.changed = sinon.stub(); |
100 |
| - } |
101 |
| - }, |
102 |
| - }, |
103 |
| - ReactiveVar: class ReactiveVar { |
104 |
| - value: any; |
105 |
| - dep: any; |
106 |
| - constructor(initialValue) { |
107 |
| - this.value = initialValue; |
108 |
| - this.dep = new (require('meteor/tracker').Tracker.Dependency)(); |
109 |
| - } |
110 |
| - |
111 |
| - get() { |
112 |
| - this.dep.depend(); |
113 |
| - return this.value; |
114 |
| - } |
115 |
| - |
116 |
| - set(newValue) { |
117 |
| - if (this.value !== newValue) { |
118 |
| - this.value = newValue; |
119 |
| - this.dep.changed(); |
120 |
| - } |
121 |
| - } |
122 |
| - }, |
123 |
| - ReactiveDict: class ReactiveDict { |
124 |
| - dict: Map<any, any>; |
125 |
| - deps: {}; |
126 |
| - constructor(initialValues) { |
127 |
| - this.dict = new Map(); |
128 |
| - this.deps = {}; |
129 |
| - |
130 |
| - if (initialValues) { |
131 |
| - for (const [key, value] of Object.entries(initialValues)) { |
132 |
| - this.set(key, value); |
133 |
| - } |
134 |
| - } |
135 |
| - } |
136 |
| - |
137 |
| - get(key) { |
138 |
| - if (!this.deps[key]) { |
139 |
| - this.deps[key] = new Tracker.Dependency(); |
140 |
| - } |
141 |
| - this.deps[key].depend(); |
142 |
| - return this.dict.get(key); |
143 |
| - } |
144 |
| - |
145 |
| - set(key, value) { |
146 |
| - const oldValue = this.dict.get(key); |
147 |
| - if (oldValue !== value) { |
148 |
| - this.dict.set(key, value); |
149 |
| - if (this.deps[key]) { |
150 |
| - this.deps[key].changed(); |
151 |
| - } |
152 |
| - } |
153 |
| - } |
154 |
| - |
155 |
| - equals(key, value) { |
156 |
| - const currentValue = this.get(key); |
157 |
| - return currentValue === value; |
158 |
| - } |
159 |
| - |
160 |
| - all() { |
161 |
| - return Object.fromEntries(this.dict); |
162 |
| - } |
163 |
| - }, |
| 3 | +export const Meteor = { |
| 4 | + loginWithSamlToken: sinon.stub(), |
164 | 5 | };
|
0 commit comments