@neurosity/sdk 6.5.10 → 6.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/neurosity.iife.js +118 -49
- package/dist/browser/neurosity.js +112 -112
- package/dist/browser/neurosity.js.map +1 -1
- package/dist/cjs/__tests__/Neurosity.test.d.ts +1 -0
- package/dist/cjs/__tests__/Neurosity.test.js +201 -0
- package/dist/cjs/__tests__/WebBluetoothTransport.test.d.ts +1 -0
- package/dist/cjs/__tests__/WebBluetoothTransport.test.js +201 -0
- package/dist/cjs/__tests__/accelerometer.test.d.ts +1 -0
- package/dist/cjs/__tests__/accelerometer.test.js +158 -0
- package/dist/cjs/__tests__/auth.test.d.ts +1 -0
- package/dist/cjs/__tests__/auth.test.js +239 -0
- package/dist/cjs/__tests__/brainwaves.test.d.ts +1 -0
- package/dist/cjs/__tests__/brainwaves.test.js +291 -0
- package/dist/cjs/__tests__/device.test.d.ts +1 -0
- package/dist/cjs/__tests__/device.test.js +281 -0
- package/dist/cjs/__tests__/haptics.test.d.ts +1 -0
- package/dist/cjs/__tests__/haptics.test.js +162 -0
- package/dist/cjs/__tests__/metrics.test.d.ts +1 -0
- package/dist/cjs/__tests__/metrics.test.js +178 -0
- package/dist/cjs/__tests__/oauth.test.d.ts +1 -0
- package/dist/cjs/__tests__/oauth.test.js +138 -0
- package/dist/cjs/__tests__/settings.test.d.ts +1 -0
- package/dist/cjs/__tests__/settings.test.js +130 -0
- package/dist/cjs/__tests__/setup/webBluetooth.setup.d.ts +11 -0
- package/dist/cjs/__tests__/setup/webBluetooth.setup.js +35 -0
- package/dist/cjs/__tests__/setup.d.ts +0 -0
- package/dist/cjs/__tests__/setup.js +7 -0
- package/dist/cjs/__tests__/streaming.test.d.ts +1 -0
- package/dist/cjs/__tests__/streaming.test.js +259 -0
- package/dist/cjs/__tests__/timesync.test.d.ts +1 -0
- package/dist/cjs/__tests__/timesync.test.js +54 -0
- package/dist/cjs/__tests__/utils.test.d.ts +1 -0
- package/dist/cjs/__tests__/utils.test.js +281 -0
- package/dist/cjs/api/bluetooth/BluetoothClient.d.ts +6 -6
- package/dist/cjs/api/bluetooth/BluetoothTransport.d.ts +1 -1
- package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.d.ts +4 -4
- package/dist/cjs/api/bluetooth/react-native/types/ReactNativeTypes.d.ts +2 -2
- package/dist/cjs/api/bluetooth/types/index.d.ts +2 -2
- package/dist/cjs/api/bluetooth/utils/decodeJSONChunks.d.ts +1 -1
- package/dist/cjs/api/bluetooth/utils/stitch.d.ts +1 -1
- package/dist/cjs/api/bluetooth/utils/textCodec.d.ts +1 -1
- package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.d.ts +1 -1
- package/dist/cjs/api/firebase/FirebaseDevice.d.ts +1 -1
- package/dist/cjs/api/firebase/FirebaseUser.d.ts +1 -1
- package/dist/cjs/api/index.js +1 -1
- package/dist/cjs/timesync/Timesync.d.ts +1 -1
- package/dist/cjs/types/awareness.d.ts +1 -1
- package/dist/cjs/types/brainwaves.d.ts +25 -12
- package/dist/cjs/types/credentials.d.ts +4 -4
- package/dist/cjs/types/deviceInfo.d.ts +4 -4
- package/dist/cjs/types/epoch.d.ts +1 -1
- package/dist/cjs/types/experiment.d.ts +1 -1
- package/dist/cjs/types/hapticEffects.d.ts +1 -1
- package/dist/cjs/types/marker.d.ts +1 -1
- package/dist/cjs/types/metrics.d.ts +2 -2
- package/dist/cjs/types/oauth.d.ts +4 -4
- package/dist/cjs/types/sample.d.ts +2 -2
- package/dist/cjs/types/signalQuality.d.ts +1 -1
- package/dist/cjs/types/skill.d.ts +2 -2
- package/dist/cjs/types/user.d.ts +3 -3
- package/dist/cjs/utils/oauth.d.ts +1 -1
- package/dist/cjs/utils/transferDevice.d.ts +3 -3
- package/dist/cjs/utils/whileOnline.d.ts +1 -1
- package/dist/electron/index.js +1 -1
- package/dist/electron/index.js.map +1 -1
- package/dist/esm/__tests__/Neurosity.test.d.ts +1 -0
- package/dist/esm/__tests__/Neurosity.test.js +199 -0
- package/dist/esm/__tests__/WebBluetoothTransport.test.d.ts +1 -0
- package/dist/esm/__tests__/WebBluetoothTransport.test.js +199 -0
- package/dist/esm/__tests__/accelerometer.test.d.ts +1 -0
- package/dist/esm/__tests__/accelerometer.test.js +156 -0
- package/dist/esm/__tests__/auth.test.d.ts +1 -0
- package/dist/esm/__tests__/auth.test.js +237 -0
- package/dist/esm/__tests__/brainwaves.test.d.ts +1 -0
- package/dist/esm/__tests__/brainwaves.test.js +289 -0
- package/dist/esm/__tests__/device.test.d.ts +1 -0
- package/dist/esm/__tests__/device.test.js +279 -0
- package/dist/esm/__tests__/haptics.test.d.ts +1 -0
- package/dist/esm/__tests__/haptics.test.js +160 -0
- package/dist/esm/__tests__/metrics.test.d.ts +1 -0
- package/dist/esm/__tests__/metrics.test.js +176 -0
- package/dist/esm/__tests__/oauth.test.d.ts +1 -0
- package/dist/esm/__tests__/oauth.test.js +133 -0
- package/dist/esm/__tests__/settings.test.d.ts +1 -0
- package/dist/esm/__tests__/settings.test.js +128 -0
- package/dist/esm/__tests__/setup/webBluetooth.setup.d.ts +11 -0
- package/dist/esm/__tests__/setup/webBluetooth.setup.js +35 -0
- package/dist/esm/__tests__/setup.d.ts +0 -0
- package/dist/esm/__tests__/setup.js +7 -0
- package/dist/esm/__tests__/streaming.test.d.ts +1 -0
- package/dist/esm/__tests__/streaming.test.js +257 -0
- package/dist/esm/__tests__/timesync.test.d.ts +1 -0
- package/dist/esm/__tests__/timesync.test.js +52 -0
- package/dist/esm/__tests__/utils.test.d.ts +1 -0
- package/dist/esm/__tests__/utils.test.js +279 -0
- package/dist/esm/api/bluetooth/BluetoothClient.d.ts +6 -6
- package/dist/esm/api/bluetooth/BluetoothTransport.d.ts +1 -1
- package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.d.ts +4 -4
- package/dist/esm/api/bluetooth/react-native/types/ReactNativeTypes.d.ts +2 -2
- package/dist/esm/api/bluetooth/types/index.d.ts +2 -2
- package/dist/esm/api/bluetooth/utils/decodeJSONChunks.d.ts +1 -1
- package/dist/esm/api/bluetooth/utils/stitch.d.ts +1 -1
- package/dist/esm/api/bluetooth/utils/textCodec.d.ts +1 -1
- package/dist/esm/api/bluetooth/web/WebBluetoothTransport.d.ts +1 -1
- package/dist/esm/api/firebase/FirebaseDevice.d.ts +1 -1
- package/dist/esm/api/firebase/FirebaseUser.d.ts +1 -1
- package/dist/esm/api/index.js +2 -2
- package/dist/esm/neurosity.mjs +118 -49
- package/dist/esm/timesync/Timesync.d.ts +1 -1
- package/dist/esm/types/awareness.d.ts +1 -1
- package/dist/esm/types/brainwaves.d.ts +25 -12
- package/dist/esm/types/credentials.d.ts +4 -4
- package/dist/esm/types/deviceInfo.d.ts +4 -4
- package/dist/esm/types/epoch.d.ts +1 -1
- package/dist/esm/types/experiment.d.ts +1 -1
- package/dist/esm/types/hapticEffects.d.ts +1 -1
- package/dist/esm/types/marker.d.ts +1 -1
- package/dist/esm/types/metrics.d.ts +2 -2
- package/dist/esm/types/oauth.d.ts +4 -4
- package/dist/esm/types/sample.d.ts +2 -2
- package/dist/esm/types/signalQuality.d.ts +1 -1
- package/dist/esm/types/skill.d.ts +2 -2
- package/dist/esm/types/user.d.ts +3 -3
- package/dist/esm/utils/oauth.d.ts +1 -1
- package/dist/esm/utils/transferDevice.d.ts +3 -3
- package/dist/esm/utils/whileOnline.d.ts +1 -1
- package/dist/examples/neurosity.iife.js +118 -49
- package/dist/examples/neurosity.js +112 -112
- package/dist/examples/neurosity.mjs +118 -49
- package/package.json +16 -4
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { Neurosity } from "../Neurosity";
|
|
11
|
+
import { BehaviorSubject, take } from "rxjs";
|
|
12
|
+
// Mock CloudClient
|
|
13
|
+
jest.mock("../api", () => {
|
|
14
|
+
const originalModule = jest.requireActual("../api");
|
|
15
|
+
class MockCloudClient {
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.user = null;
|
|
18
|
+
this.userClaims = { scopes: ["brainwaves"] };
|
|
19
|
+
this.subscriptionManager = {
|
|
20
|
+
add: jest.fn(),
|
|
21
|
+
remove: jest.fn(),
|
|
22
|
+
removeAll: jest.fn()
|
|
23
|
+
};
|
|
24
|
+
this._selectedDevice = new BehaviorSubject(undefined);
|
|
25
|
+
this._authStateSubject = new BehaviorSubject(null);
|
|
26
|
+
this.login = jest.fn().mockImplementation((credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
if (credentials.email === "invalid@example.com") {
|
|
28
|
+
throw new Error("Invalid credentials");
|
|
29
|
+
}
|
|
30
|
+
this._authStateSubject.next({ email: credentials.email });
|
|
31
|
+
return { user: { email: credentials.email } };
|
|
32
|
+
}));
|
|
33
|
+
this.logout = jest.fn().mockImplementation(() => __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
this._authStateSubject.next(null);
|
|
35
|
+
return {};
|
|
36
|
+
}));
|
|
37
|
+
this.createAccount = jest.fn().mockImplementation((credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
var _a;
|
|
39
|
+
if ((_a = this._existingAccounts) === null || _a === void 0 ? void 0 : _a.includes(credentials.email)) {
|
|
40
|
+
throw new Error("Account already exists");
|
|
41
|
+
}
|
|
42
|
+
if (!this._existingAccounts) {
|
|
43
|
+
this._existingAccounts = [];
|
|
44
|
+
}
|
|
45
|
+
this._existingAccounts.push(credentials.email);
|
|
46
|
+
return { user: { email: credentials.email } };
|
|
47
|
+
}));
|
|
48
|
+
this.deleteAccount = jest.fn().mockImplementation(() => __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
this._authStateSubject.next(null);
|
|
50
|
+
return {};
|
|
51
|
+
}));
|
|
52
|
+
this.onAuthStateChanged = jest.fn().mockImplementation(() => {
|
|
53
|
+
return this._authStateSubject.asObservable();
|
|
54
|
+
});
|
|
55
|
+
this._existingAccounts = [];
|
|
56
|
+
this.options = options;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return Object.assign(Object.assign({}, originalModule), { CloudClient: jest
|
|
60
|
+
.fn()
|
|
61
|
+
.mockImplementation((options) => new MockCloudClient(options)) });
|
|
62
|
+
});
|
|
63
|
+
describe("Authentication", () => {
|
|
64
|
+
let neurosity;
|
|
65
|
+
const testDeviceId = "test-device-id";
|
|
66
|
+
const credentials = {
|
|
67
|
+
email: "test@example.com",
|
|
68
|
+
password: "testPassword123"
|
|
69
|
+
};
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
neurosity = new Neurosity({
|
|
72
|
+
deviceId: testDeviceId,
|
|
73
|
+
emulator: true
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
afterEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
|
+
try {
|
|
78
|
+
yield neurosity.logout();
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
// Ignore logout errors in cleanup
|
|
82
|
+
}
|
|
83
|
+
}));
|
|
84
|
+
describe("Basic Authentication", () => {
|
|
85
|
+
it("should handle login and logout flow", (done) => {
|
|
86
|
+
neurosity.login(credentials).then(() => {
|
|
87
|
+
neurosity
|
|
88
|
+
.onAuthStateChanged()
|
|
89
|
+
.pipe(take(1))
|
|
90
|
+
.subscribe({
|
|
91
|
+
next: (authState) => {
|
|
92
|
+
expect(authState).toBeTruthy();
|
|
93
|
+
expect(authState.email).toBe(credentials.email);
|
|
94
|
+
done();
|
|
95
|
+
},
|
|
96
|
+
error: done
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
it("should handle logout", (done) => {
|
|
101
|
+
neurosity.login(credentials).then(() => {
|
|
102
|
+
neurosity.logout().then(() => {
|
|
103
|
+
neurosity
|
|
104
|
+
.onAuthStateChanged()
|
|
105
|
+
.pipe(take(1))
|
|
106
|
+
.subscribe({
|
|
107
|
+
next: (loggedOutState) => {
|
|
108
|
+
expect(loggedOutState).toBeFalsy();
|
|
109
|
+
done();
|
|
110
|
+
},
|
|
111
|
+
error: done
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
it("should reject invalid credentials", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
const invalidCredentials = {
|
|
118
|
+
email: "invalid@example.com",
|
|
119
|
+
password: "wrongPassword"
|
|
120
|
+
};
|
|
121
|
+
yield expect(neurosity.login(invalidCredentials)).rejects.toThrow("Invalid credentials");
|
|
122
|
+
}));
|
|
123
|
+
});
|
|
124
|
+
describe("Account Management", () => {
|
|
125
|
+
it("should create account", (done) => {
|
|
126
|
+
const newAccount = {
|
|
127
|
+
email: "new@example.com",
|
|
128
|
+
password: "newPassword123"
|
|
129
|
+
};
|
|
130
|
+
neurosity.createAccount(newAccount).then(() => {
|
|
131
|
+
neurosity.login(newAccount).then(() => {
|
|
132
|
+
neurosity
|
|
133
|
+
.onAuthStateChanged()
|
|
134
|
+
.pipe(take(1))
|
|
135
|
+
.subscribe({
|
|
136
|
+
next: (authState) => {
|
|
137
|
+
expect(authState).toBeTruthy();
|
|
138
|
+
expect(authState.email).toBe(newAccount.email);
|
|
139
|
+
done();
|
|
140
|
+
},
|
|
141
|
+
error: done
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
it("should delete account", (done) => {
|
|
147
|
+
const account = {
|
|
148
|
+
email: "delete@example.com",
|
|
149
|
+
password: "deletePassword123"
|
|
150
|
+
};
|
|
151
|
+
neurosity.createAccount(account).then(() => {
|
|
152
|
+
neurosity.login(account).then(() => {
|
|
153
|
+
neurosity.deleteAccount().then(() => {
|
|
154
|
+
neurosity
|
|
155
|
+
.onAuthStateChanged()
|
|
156
|
+
.pipe(take(1))
|
|
157
|
+
.subscribe({
|
|
158
|
+
next: (deletedState) => {
|
|
159
|
+
expect(deletedState).toBeFalsy();
|
|
160
|
+
done();
|
|
161
|
+
},
|
|
162
|
+
error: done
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
it("should prevent duplicate account creation", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
169
|
+
const existingAccount = {
|
|
170
|
+
email: "existing@example.com",
|
|
171
|
+
password: "existingPassword123"
|
|
172
|
+
};
|
|
173
|
+
yield expect(neurosity.createAccount(existingAccount)).resolves.not.toThrow();
|
|
174
|
+
yield expect(neurosity.createAccount(existingAccount)).rejects.toThrow("Account already exists");
|
|
175
|
+
// Cleanup
|
|
176
|
+
yield neurosity.login(existingAccount);
|
|
177
|
+
yield neurosity.deleteAccount();
|
|
178
|
+
}));
|
|
179
|
+
});
|
|
180
|
+
describe("Auth State Changes", () => {
|
|
181
|
+
it("should emit initial auth state", (done) => {
|
|
182
|
+
neurosity
|
|
183
|
+
.onAuthStateChanged()
|
|
184
|
+
.pipe(take(1))
|
|
185
|
+
.subscribe({
|
|
186
|
+
next: (state) => {
|
|
187
|
+
expect(state).toBeFalsy(); // Initial state should be null
|
|
188
|
+
done();
|
|
189
|
+
},
|
|
190
|
+
error: done
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
it("should emit logged in state", (done) => {
|
|
194
|
+
neurosity.login(credentials).then(() => {
|
|
195
|
+
neurosity
|
|
196
|
+
.onAuthStateChanged()
|
|
197
|
+
.pipe(take(1))
|
|
198
|
+
.subscribe({
|
|
199
|
+
next: (loggedInState) => {
|
|
200
|
+
expect(loggedInState).toBeTruthy();
|
|
201
|
+
expect(loggedInState.email).toBe(credentials.email);
|
|
202
|
+
done();
|
|
203
|
+
},
|
|
204
|
+
error: done
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
it("should handle session expiration", (done) => {
|
|
209
|
+
neurosity.login(credentials).then(() => {
|
|
210
|
+
const cloudClient = neurosity.cloudClient;
|
|
211
|
+
cloudClient._authStateSubject.next(null);
|
|
212
|
+
neurosity
|
|
213
|
+
.onAuthStateChanged()
|
|
214
|
+
.pipe(take(1))
|
|
215
|
+
.subscribe({
|
|
216
|
+
next: (expiredState) => {
|
|
217
|
+
expect(expiredState).toBeFalsy();
|
|
218
|
+
done();
|
|
219
|
+
},
|
|
220
|
+
error: done
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
describe("Error Handling", () => {
|
|
226
|
+
it("should handle network errors during login", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
227
|
+
const cloudClient = neurosity.cloudClient;
|
|
228
|
+
cloudClient.login.mockRejectedValueOnce(new Error("Network error"));
|
|
229
|
+
yield expect(neurosity.login(credentials)).rejects.toThrow("Network error");
|
|
230
|
+
}));
|
|
231
|
+
it("should handle server errors during account creation", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
232
|
+
const cloudClient = neurosity.cloudClient;
|
|
233
|
+
cloudClient.createAccount.mockRejectedValueOnce(new Error("Server error"));
|
|
234
|
+
yield expect(neurosity.createAccount(credentials)).rejects.toThrow("Server error");
|
|
235
|
+
}));
|
|
236
|
+
});
|
|
237
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { Neurosity } from "../Neurosity";
|
|
11
|
+
import { firstValueFrom, of, ReplaySubject } from "rxjs";
|
|
12
|
+
import { STATUS } from "../types/status";
|
|
13
|
+
import { MODEL_VERSION_2 } from "../utils/platform";
|
|
14
|
+
// Mock CloudClient
|
|
15
|
+
jest.mock("../api", () => {
|
|
16
|
+
const originalModule = jest.requireActual("../api");
|
|
17
|
+
class MockCloudClient {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
this.user = null;
|
|
20
|
+
this.userClaims = { scopes: ["brainwaves"] };
|
|
21
|
+
this.subscriptionManager = {
|
|
22
|
+
add: jest.fn(),
|
|
23
|
+
remove: jest.fn(),
|
|
24
|
+
removeAll: jest.fn()
|
|
25
|
+
};
|
|
26
|
+
this._selectedDevice = new ReplaySubject(1);
|
|
27
|
+
this._deviceInfo = {
|
|
28
|
+
deviceId: "test-device-id",
|
|
29
|
+
deviceNickname: "Test Device",
|
|
30
|
+
channelNames: ["CH1", "CH2"],
|
|
31
|
+
channels: 2,
|
|
32
|
+
samplingRate: 250,
|
|
33
|
+
manufacturer: "Neurosity",
|
|
34
|
+
model: "Crown",
|
|
35
|
+
modelName: "Crown",
|
|
36
|
+
modelVersion: MODEL_VERSION_2,
|
|
37
|
+
apiVersion: "1.0.0",
|
|
38
|
+
osVersion: "1.0.0",
|
|
39
|
+
emulator: false
|
|
40
|
+
};
|
|
41
|
+
this.getInfo = jest.fn().mockResolvedValue(this._deviceInfo);
|
|
42
|
+
this.selectDevice = jest
|
|
43
|
+
.fn()
|
|
44
|
+
.mockImplementation((selector) => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const selectedDevice = selector([this._deviceInfo]);
|
|
46
|
+
this._selectedDevice.next(selectedDevice);
|
|
47
|
+
return selectedDevice;
|
|
48
|
+
}));
|
|
49
|
+
this.getSelectedDevice = jest.fn().mockResolvedValue(this._deviceInfo);
|
|
50
|
+
this.didSelectDevice = jest.fn().mockResolvedValue(true);
|
|
51
|
+
this.onDeviceChange = jest.fn().mockReturnValue(of({
|
|
52
|
+
state: STATUS.ONLINE,
|
|
53
|
+
charging: false,
|
|
54
|
+
battery: 100,
|
|
55
|
+
sleepMode: false,
|
|
56
|
+
updatingProgress: 0,
|
|
57
|
+
bluetoothEnabled: false,
|
|
58
|
+
sleepModeReason: null,
|
|
59
|
+
lastHeartbeat: Date.now(),
|
|
60
|
+
ssid: "test-network"
|
|
61
|
+
}));
|
|
62
|
+
this.status = jest.fn().mockReturnValue(of({
|
|
63
|
+
state: STATUS.ONLINE,
|
|
64
|
+
charging: false,
|
|
65
|
+
battery: 100,
|
|
66
|
+
sleepMode: false,
|
|
67
|
+
updatingProgress: 0,
|
|
68
|
+
bluetoothEnabled: false,
|
|
69
|
+
sleepModeReason: null,
|
|
70
|
+
lastHeartbeat: Date.now(),
|
|
71
|
+
ssid: "test-network"
|
|
72
|
+
}));
|
|
73
|
+
this.osVersion = jest.fn().mockReturnValue(of("1.0.0"));
|
|
74
|
+
this.metrics = {
|
|
75
|
+
subscribe: jest.fn().mockImplementation((subscription) => {
|
|
76
|
+
return subscription;
|
|
77
|
+
}),
|
|
78
|
+
unsubscribe: jest.fn(),
|
|
79
|
+
on: jest.fn().mockImplementation((subscription, callback) => {
|
|
80
|
+
switch (subscription.labels[0]) {
|
|
81
|
+
case "raw":
|
|
82
|
+
callback({
|
|
83
|
+
data: [
|
|
84
|
+
[100, 200],
|
|
85
|
+
[150, 250]
|
|
86
|
+
],
|
|
87
|
+
info: {
|
|
88
|
+
samplingRate: 250,
|
|
89
|
+
startTime: Date.now(),
|
|
90
|
+
notchFrequency: "60Hz",
|
|
91
|
+
channelNames: [
|
|
92
|
+
"CP3",
|
|
93
|
+
"C3",
|
|
94
|
+
"F5",
|
|
95
|
+
"PO3",
|
|
96
|
+
"PO4",
|
|
97
|
+
"F6",
|
|
98
|
+
"C4",
|
|
99
|
+
"CP4"
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
break;
|
|
104
|
+
case "rawUnfiltered":
|
|
105
|
+
callback({
|
|
106
|
+
data: [
|
|
107
|
+
[100, 200],
|
|
108
|
+
[150, 250]
|
|
109
|
+
],
|
|
110
|
+
info: {
|
|
111
|
+
samplingRate: 250,
|
|
112
|
+
startTime: Date.now(),
|
|
113
|
+
channelNames: [
|
|
114
|
+
"CP3",
|
|
115
|
+
"C3",
|
|
116
|
+
"F5",
|
|
117
|
+
"PO3",
|
|
118
|
+
"PO4",
|
|
119
|
+
"F6",
|
|
120
|
+
"C4",
|
|
121
|
+
"CP4"
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
break;
|
|
126
|
+
case "powerByBand":
|
|
127
|
+
callback({
|
|
128
|
+
gamma: [0.5, 0.6],
|
|
129
|
+
beta: [0.4, 0.5],
|
|
130
|
+
alpha: [0.3, 0.4],
|
|
131
|
+
theta: [0.2, 0.3],
|
|
132
|
+
delta: [0.1, 0.2],
|
|
133
|
+
info: {
|
|
134
|
+
channelNames: [
|
|
135
|
+
"CP3",
|
|
136
|
+
"C3",
|
|
137
|
+
"F5",
|
|
138
|
+
"PO3",
|
|
139
|
+
"PO4",
|
|
140
|
+
"F6",
|
|
141
|
+
"C4",
|
|
142
|
+
"CP4"
|
|
143
|
+
],
|
|
144
|
+
samplingRate: 256,
|
|
145
|
+
startTime: Date.now()
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
break;
|
|
149
|
+
case "psd":
|
|
150
|
+
callback({
|
|
151
|
+
label: "psd",
|
|
152
|
+
psd: [
|
|
153
|
+
[0.1, 0.2],
|
|
154
|
+
[0.3, 0.4]
|
|
155
|
+
],
|
|
156
|
+
freqs: [1, 2],
|
|
157
|
+
info: {
|
|
158
|
+
notchFrequency: "60Hz",
|
|
159
|
+
samplingRate: 250,
|
|
160
|
+
startTime: Date.now(),
|
|
161
|
+
channelNames: [
|
|
162
|
+
"CP3",
|
|
163
|
+
"C3",
|
|
164
|
+
"F5",
|
|
165
|
+
"PO3",
|
|
166
|
+
"PO4",
|
|
167
|
+
"F6",
|
|
168
|
+
"C4",
|
|
169
|
+
"CP4"
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
break;
|
|
174
|
+
default:
|
|
175
|
+
throw new Error(`One ore more labels provided to brainwaves are invalid. The valid labels for brainwaves are raw, rawUnfiltered, frequency, powerByBand, psd`);
|
|
176
|
+
}
|
|
177
|
+
return () => { };
|
|
178
|
+
})
|
|
179
|
+
};
|
|
180
|
+
this.options = options;
|
|
181
|
+
this._selectedDevice.next(this._deviceInfo);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return Object.assign(Object.assign({}, originalModule), { CloudClient: jest
|
|
185
|
+
.fn()
|
|
186
|
+
.mockImplementation((options) => new MockCloudClient(options)) });
|
|
187
|
+
});
|
|
188
|
+
describe("Brainwaves", () => {
|
|
189
|
+
let neurosity;
|
|
190
|
+
const testDeviceId = "test-device-id";
|
|
191
|
+
beforeEach(() => {
|
|
192
|
+
neurosity = new Neurosity({
|
|
193
|
+
deviceId: testDeviceId,
|
|
194
|
+
emulator: true
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
describe("Raw Brainwaves", () => {
|
|
198
|
+
it("should get raw brainwaves data", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
199
|
+
const data = (yield firstValueFrom(neurosity.brainwaves("raw")));
|
|
200
|
+
expect(data).toBeDefined();
|
|
201
|
+
expect(data.data).toBeInstanceOf(Array);
|
|
202
|
+
expect(data.data[0]).toBeInstanceOf(Array);
|
|
203
|
+
expect(data.info.samplingRate).toBe(250);
|
|
204
|
+
expect(data.info.startTime).toBeDefined();
|
|
205
|
+
expect(data.info.notchFrequency).toBe("60Hz");
|
|
206
|
+
expect(data.info.channelNames).toEqual([
|
|
207
|
+
"CP3",
|
|
208
|
+
"C3",
|
|
209
|
+
"F5",
|
|
210
|
+
"PO3",
|
|
211
|
+
"PO4",
|
|
212
|
+
"F6",
|
|
213
|
+
"C4",
|
|
214
|
+
"CP4"
|
|
215
|
+
]);
|
|
216
|
+
}));
|
|
217
|
+
it("should get raw unfiltered brainwaves data", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
218
|
+
const data = (yield firstValueFrom(neurosity.brainwaves("rawUnfiltered")));
|
|
219
|
+
expect(data).toBeDefined();
|
|
220
|
+
expect(data.data).toBeInstanceOf(Array);
|
|
221
|
+
expect(data.data[0]).toBeInstanceOf(Array);
|
|
222
|
+
expect(data.info.samplingRate).toBe(250);
|
|
223
|
+
expect(data.info.startTime).toBeDefined();
|
|
224
|
+
expect(data.info.channelNames).toEqual([
|
|
225
|
+
"CP3",
|
|
226
|
+
"C3",
|
|
227
|
+
"F5",
|
|
228
|
+
"PO3",
|
|
229
|
+
"PO4",
|
|
230
|
+
"F6",
|
|
231
|
+
"C4",
|
|
232
|
+
"CP4"
|
|
233
|
+
]);
|
|
234
|
+
expect(data.info.notchFrequency).toBeUndefined();
|
|
235
|
+
}));
|
|
236
|
+
});
|
|
237
|
+
describe("Power by Band", () => {
|
|
238
|
+
it("should get power by band data", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
239
|
+
const data = (yield firstValueFrom(neurosity.brainwaves("powerByBand")));
|
|
240
|
+
expect(data).toBeDefined();
|
|
241
|
+
expect(data.gamma).toBeInstanceOf(Array);
|
|
242
|
+
expect(data.beta).toBeInstanceOf(Array);
|
|
243
|
+
expect(data.alpha).toBeInstanceOf(Array);
|
|
244
|
+
expect(data.theta).toBeInstanceOf(Array);
|
|
245
|
+
expect(data.delta).toBeInstanceOf(Array);
|
|
246
|
+
// Verify info object exists and has correct properties
|
|
247
|
+
expect(data.info).toBeDefined();
|
|
248
|
+
expect(data.info.samplingRate).toBe(256);
|
|
249
|
+
expect(data.info.startTime).toBeDefined();
|
|
250
|
+
expect(data.info.channelNames).toEqual([
|
|
251
|
+
"CP3",
|
|
252
|
+
"C3",
|
|
253
|
+
"F5",
|
|
254
|
+
"PO3",
|
|
255
|
+
"PO4",
|
|
256
|
+
"F6",
|
|
257
|
+
"C4",
|
|
258
|
+
"CP4"
|
|
259
|
+
]);
|
|
260
|
+
}));
|
|
261
|
+
});
|
|
262
|
+
describe("Power Spectral Density", () => {
|
|
263
|
+
it("should get PSD data", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
264
|
+
const data = (yield firstValueFrom(neurosity.brainwaves("psd")));
|
|
265
|
+
expect(data).toBeDefined();
|
|
266
|
+
expect(data.label).toBe("psd");
|
|
267
|
+
expect(data.psd).toBeInstanceOf(Array);
|
|
268
|
+
expect(data.freqs).toBeInstanceOf(Array);
|
|
269
|
+
expect(data.info.samplingRate).toBe(250);
|
|
270
|
+
expect(data.info.startTime).toBeDefined();
|
|
271
|
+
expect(data.info.notchFrequency).toBe("60Hz");
|
|
272
|
+
expect(data.info.channelNames).toEqual([
|
|
273
|
+
"CP3",
|
|
274
|
+
"C3",
|
|
275
|
+
"F5",
|
|
276
|
+
"PO3",
|
|
277
|
+
"PO4",
|
|
278
|
+
"F6",
|
|
279
|
+
"C4",
|
|
280
|
+
"CP4"
|
|
281
|
+
]);
|
|
282
|
+
}));
|
|
283
|
+
});
|
|
284
|
+
describe("Error Handling", () => {
|
|
285
|
+
it("should handle invalid brainwaves label", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
286
|
+
yield expect(firstValueFrom(neurosity.brainwaves("invalid"))).rejects.toThrow("One ore more labels provided to brainwaves are invalid. The valid labels for brainwaves are raw, rawUnfiltered, frequency, powerByBand, psd");
|
|
287
|
+
}));
|
|
288
|
+
});
|
|
289
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|