Skip to content

Commit 8b340c1

Browse files
Extend Jasmine tests with events and requests
1 parent f82be2a commit 8b340c1

File tree

10 files changed

+370
-97
lines changed

10 files changed

+370
-97
lines changed

application/apps/indexer/session/src/events.rs

+1
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ impl std::fmt::Display for CallbackEvent {
312312
}
313313
}
314314

315+
#[enum_ids(derive = "Debug")]
315316
#[derive(Debug, Serialize, Deserialize, Clone)]
316317
pub enum LifecycleTransition {
317318
Started { uuid: Uuid, alias: String },

application/apps/indexer/session/src/progress.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{
22
events::{ComputationError, LifecycleTransition},
33
TRACKER_CHANNEL,
44
};
5+
use enum_ids::enum_ids;
56
use log::{error, info};
67
use serde::{Deserialize, Serialize};
78
use std::collections::HashMap;
@@ -21,6 +22,7 @@ pub struct Notification {
2122
pub line: Option<usize>,
2223
}
2324

25+
#[enum_ids(derive = "Debug")]
2426
#[derive(Debug, Serialize, Deserialize)]
2527
#[serde(tag = "type")]
2628
pub enum Progress {

application/apps/rustcore/rs-bindings/src/js/converting/event.rs

+111-52
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use node_bindgen::{
88
use proto::*;
99
use session::{
1010
events::{CallbackEvent, CallbackEventId, NativeError, NativeErrorKind, OperationDone},
11-
progress::{Notification, Progress, Ticks},
11+
progress::{Notification, Progress, ProgressId, Ticks},
1212
};
1313
use session::{progress::Severity, state::AttachmentInfo};
1414
use std::{collections::HashMap, mem, path::PathBuf};
@@ -157,88 +157,147 @@ pub fn test_cases() -> Vec<CallbackEventWrapped> {
157157
.into_iter()
158158
.flat_map(|id| match id {
159159
CallbackEventId::FileRead => vec![CallbackEvent::FileRead],
160-
CallbackEventId::AttachmentsUpdated => vec![CallbackEvent::AttachmentsUpdated {
161-
len: 9,
162-
attachment: AttachmentInfo {
163-
uuid: Uuid::new_v4(),
164-
filepath: PathBuf::from("fake/path"),
165-
name: String::from("test"),
166-
ext: Some(String::from("test")),
167-
size: 999,
168-
mime: Some(String::from("media")),
169-
messages: vec![1, 2, 3, 100, 101, 102],
160+
CallbackEventId::AttachmentsUpdated => vec![
161+
CallbackEvent::AttachmentsUpdated {
162+
len: 9,
163+
attachment: AttachmentInfo {
164+
uuid: Uuid::new_v4(),
165+
filepath: PathBuf::from("fake/path"),
166+
name: String::from("test"),
167+
ext: Some(String::from("test")),
168+
size: 999,
169+
mime: Some(String::from("media")),
170+
messages: vec![1, 2, 3, 100, 101, 102],
171+
},
172+
},
173+
CallbackEvent::AttachmentsUpdated {
174+
len: 9,
175+
attachment: AttachmentInfo {
176+
uuid: Uuid::new_v4(),
177+
filepath: PathBuf::new(),
178+
name: String::new(),
179+
ext: None,
180+
size: 0,
181+
mime: None,
182+
messages: Vec::new(),
183+
},
170184
},
171-
}],
185+
],
172186
CallbackEventId::IndexedMapUpdated => {
173-
vec![CallbackEvent::IndexedMapUpdated { len: 999 }]
187+
vec![
188+
CallbackEvent::IndexedMapUpdated { len: 999 },
189+
CallbackEvent::IndexedMapUpdated { len: 0 },
190+
]
174191
}
175-
CallbackEventId::OperationDone => vec![CallbackEvent::OperationDone(OperationDone {
176-
uuid: Uuid::new_v4(),
177-
result: Some(String::from("test")),
178-
})],
179-
CallbackEventId::OperationError => vec![CallbackEvent::OperationError {
180-
uuid: Uuid::new_v4(),
181-
error: NativeError {
182-
severity: Severity::ERROR,
183-
kind: NativeErrorKind::ChannelError,
184-
message: Some(String::from("test")),
192+
CallbackEventId::OperationDone => vec![
193+
CallbackEvent::OperationDone(OperationDone {
194+
uuid: Uuid::new_v4(),
195+
result: Some(String::from("test")),
196+
}),
197+
CallbackEvent::OperationDone(OperationDone {
198+
uuid: Uuid::new_v4(),
199+
result: None,
200+
}),
201+
CallbackEvent::OperationDone(OperationDone {
202+
uuid: Uuid::new_v4(),
203+
result: Some(String::new()),
204+
}),
205+
],
206+
CallbackEventId::OperationError => vec![
207+
CallbackEvent::OperationError {
208+
uuid: Uuid::new_v4(),
209+
error: NativeError {
210+
severity: Severity::ERROR,
211+
kind: NativeErrorKind::ChannelError,
212+
message: Some(String::from("test")),
213+
},
185214
},
186-
}],
215+
CallbackEvent::OperationError {
216+
uuid: Uuid::new_v4(),
217+
error: NativeError {
218+
severity: Severity::WARNING,
219+
kind: NativeErrorKind::ChannelError,
220+
message: Some(String::new()),
221+
},
222+
},
223+
CallbackEvent::OperationError {
224+
uuid: Uuid::new_v4(),
225+
error: NativeError {
226+
severity: Severity::ERROR,
227+
kind: NativeErrorKind::ChannelError,
228+
message: None,
229+
},
230+
},
231+
],
187232
CallbackEventId::OperationProcessing => {
188233
vec![CallbackEvent::OperationProcessing(Uuid::new_v4())]
189234
}
190235
CallbackEventId::OperationStarted => {
191236
vec![CallbackEvent::OperationStarted(Uuid::new_v4())]
192237
}
193-
CallbackEventId::Progress => vec![
194-
CallbackEvent::Progress {
195-
uuid: Uuid::new_v4(),
196-
progress: Progress::Ticks(Ticks {
197-
count: 1,
198-
state: Some(String::from("test")),
199-
total: Some(100),
200-
}),
201-
},
202-
CallbackEvent::Progress {
203-
uuid: Uuid::new_v4(),
204-
progress: Progress::Notification(Notification {
205-
severity: Severity::ERROR,
206-
content: String::from("test"),
207-
line: Some(999),
208-
}),
209-
},
210-
CallbackEvent::Progress {
238+
CallbackEventId::Progress => ProgressId::as_vec()
239+
.into_iter()
240+
.map(|pid| CallbackEvent::Progress {
211241
uuid: Uuid::new_v4(),
212-
progress: Progress::Stopped,
213-
},
214-
],
242+
progress: match pid {
243+
ProgressId::Notification => Progress::Notification(Notification {
244+
severity: Severity::ERROR,
245+
content: String::from("test"),
246+
line: Some(999),
247+
}),
248+
ProgressId::Stopped => Progress::Stopped,
249+
ProgressId::Ticks => Progress::Ticks(Ticks {
250+
count: 1,
251+
state: Some(String::from("test")),
252+
total: Some(100),
253+
}),
254+
},
255+
})
256+
.collect(),
215257
CallbackEventId::SearchMapUpdated => {
216-
vec![CallbackEvent::SearchMapUpdated(Some(String::from("test")))]
258+
vec![
259+
CallbackEvent::SearchMapUpdated(Some(String::from("test"))),
260+
CallbackEvent::SearchMapUpdated(Some(String::new())),
261+
CallbackEvent::SearchMapUpdated(None),
262+
]
217263
}
218264
CallbackEventId::SearchUpdated => {
219265
let mut stat = HashMap::new();
220266
stat.insert(String::from("a"), 999);
221267
stat.insert(String::from("b"), 999);
222268
stat.insert(String::from("c"), 999);
223-
vec![CallbackEvent::SearchUpdated {
224-
found: 999 * 3,
225-
stat,
226-
}]
269+
vec![
270+
CallbackEvent::SearchUpdated {
271+
found: 999 * 3,
272+
stat,
273+
},
274+
CallbackEvent::SearchUpdated {
275+
found: 0,
276+
stat: HashMap::new(),
277+
},
278+
]
227279
}
228280
CallbackEventId::SearchValuesUpdated => {
229281
let mut data = HashMap::new();
230282
data.insert(1, (1.2, 10.2));
231283
data.insert(2, (2.2, 20.2));
232284
data.insert(3, (3.2, 30.2));
233-
vec![CallbackEvent::SearchValuesUpdated(Some(data))]
285+
vec![
286+
CallbackEvent::SearchValuesUpdated(Some(data)),
287+
CallbackEvent::SearchValuesUpdated(None),
288+
CallbackEvent::SearchValuesUpdated(Some(HashMap::new())),
289+
]
234290
}
235291
CallbackEventId::SessionDestroyed => vec![CallbackEvent::SessionDestroyed],
236292
CallbackEventId::SessionError => vec![CallbackEvent::SessionError(NativeError {
237293
severity: Severity::ERROR,
238294
kind: NativeErrorKind::ChannelError,
239295
message: Some(String::from("test")),
240296
})],
241-
CallbackEventId::StreamUpdated => vec![CallbackEvent::StreamUpdated(999)],
297+
CallbackEventId::StreamUpdated => vec![
298+
CallbackEvent::StreamUpdated(999),
299+
CallbackEvent::StreamUpdated(0),
300+
],
242301
})
243302
.collect();
244303
events.into_iter().map(|ev| ev.into()).collect()

application/apps/rustcore/rs-bindings/src/js/converting/progress.rs

+63-7
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,29 @@ use node_bindgen::{
44
};
55
use progress::{self, lifecycle_transition};
66
use proto::*;
7-
use session::events::LifecycleTransition;
7+
use session::{
8+
events::{LifecycleTransition, LifecycleTransitionId},
9+
progress::Ticks,
10+
};
11+
use uuid::Uuid;
812

913
#[derive(Debug)]
10-
pub(crate) struct LifecycleTransitionWrapper(Option<LifecycleTransition>);
14+
pub(crate) struct LifecycleTransitionWrapped(Option<LifecycleTransition>);
1115

12-
impl LifecycleTransitionWrapper {
16+
impl LifecycleTransitionWrapped {
1317
pub fn new(lt: LifecycleTransition) -> Self {
14-
LifecycleTransitionWrapper(Some(lt))
18+
LifecycleTransitionWrapped(Some(lt))
19+
}
20+
}
21+
22+
impl From<LifecycleTransition> for LifecycleTransitionWrapped {
23+
fn from(ev: LifecycleTransition) -> LifecycleTransitionWrapped {
24+
LifecycleTransitionWrapped::new(ev)
1525
}
1626
}
1727

18-
impl From<LifecycleTransitionWrapper> for Vec<u8> {
19-
fn from(mut val: LifecycleTransitionWrapper) -> Self {
28+
impl From<LifecycleTransitionWrapped> for Vec<u8> {
29+
fn from(mut val: LifecycleTransitionWrapped) -> Self {
2030
let ev = val
2131
.0
2232
.take()
@@ -50,8 +60,54 @@ impl From<LifecycleTransitionWrapper> for Vec<u8> {
5060
}
5161
}
5262

53-
impl TryIntoJs for LifecycleTransitionWrapper {
63+
impl TryIntoJs for LifecycleTransitionWrapped {
5464
fn try_to_js(self, js_env: &JsEnv) -> Result<napi_value, NjError> {
5565
SafeArrayBuffer::new(self.into()).try_to_js(js_env)
5666
}
5767
}
68+
69+
pub fn test_cases() -> Vec<LifecycleTransitionWrapped> {
70+
let events: Vec<LifecycleTransition> = LifecycleTransitionId::as_vec()
71+
.into_iter()
72+
.flat_map(|id| match id {
73+
LifecycleTransitionId::Started => vec![
74+
LifecycleTransition::Started {
75+
uuid: Uuid::new_v4(),
76+
alias: String::from("test"),
77+
},
78+
LifecycleTransition::Started {
79+
uuid: Uuid::new_v4(),
80+
alias: String::new(),
81+
},
82+
],
83+
LifecycleTransitionId::Stopped => vec![LifecycleTransition::Stopped(Uuid::new_v4())],
84+
LifecycleTransitionId::Ticks => vec![
85+
LifecycleTransition::Ticks {
86+
uuid: Uuid::new_v4(),
87+
ticks: Ticks {
88+
count: 1,
89+
state: Some(String::from("test")),
90+
total: Some(100),
91+
},
92+
},
93+
LifecycleTransition::Ticks {
94+
uuid: Uuid::new_v4(),
95+
ticks: Ticks {
96+
count: 0,
97+
state: Some(String::new()),
98+
total: Some(0),
99+
},
100+
},
101+
LifecycleTransition::Ticks {
102+
uuid: Uuid::new_v4(),
103+
ticks: Ticks {
104+
count: 0,
105+
state: None,
106+
total: None,
107+
},
108+
},
109+
],
110+
})
111+
.collect();
112+
events.into_iter().map(|ev| ev.into()).collect()
113+
}

application/apps/rustcore/rs-bindings/src/js/session/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::{
77
event::{self, CallbackEventWrapped},
88
filter::WrappedSearchFilter,
99
grabbing::GrabbedElements,
10+
progress,
1011
ranges::RangeInclusiveList,
1112
sde::SdeResponseWrapped,
1213
source::WrappedSourceDefinition,
@@ -739,4 +740,12 @@ impl RustSession {
739740
.map(|ev| SafeArrayBuffer::new(ev.into()))
740741
.collect::<Vec<SafeArrayBuffer>>())
741742
}
743+
744+
#[node_bindgen]
745+
fn test_lt_events_as_proto(&self) -> Result<Vec<SafeArrayBuffer>, ComputationErrorWrapper> {
746+
Ok(progress::test_cases()
747+
.into_iter()
748+
.map(|ev| SafeArrayBuffer::new(ev.into()))
749+
.collect::<Vec<SafeArrayBuffer>>())
750+
}
742751
}

application/apps/rustcore/rs-bindings/src/js/session/progress_tracker.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::js::converting::{
2-
errors::ComputationErrorWrapper, progress::LifecycleTransitionWrapper,
2+
errors::ComputationErrorWrapper, progress::LifecycleTransitionWrapped,
33
};
44
use log::trace;
55
use node_bindgen::derive::node_bindgen;
@@ -27,7 +27,7 @@ impl RustProgressTracker {
2727
}
2828

2929
#[node_bindgen(mt)]
30-
async fn init<F: Fn(LifecycleTransitionWrapper) + Send + 'static>(
30+
async fn init<F: Fn(LifecycleTransitionWrapped) + Send + 'static>(
3131
&mut self,
3232
callback: F,
3333
) -> Result<(), ComputationErrorWrapper> {
@@ -43,7 +43,7 @@ impl RustProgressTracker {
4343
Ok(mut rx) => {
4444
let _ = result_tx.send(Ok(()));
4545
while let Some(progress_report) = rx.recv().await {
46-
callback(LifecycleTransitionWrapper::new(progress_report))
46+
callback(LifecycleTransitionWrapped::new(progress_report))
4747
}
4848
}
4949
Err(e) => {

application/apps/rustcore/ts-bindings/spec/defaults.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
"list": {
3535
"1": "Test 1. CallbackEvent",
3636
"2": "Test 2. Comparing JSON vs Protobuf",
37-
"3": "Test 3. All CallbackEvens as Protobuf"
37+
"3": "Test 3. All CallbackEvens as Protobuf",
38+
"4": "Test 4. All LifecycleTransition as Protobuf"
39+
3840
},
3941
"files": {
4042
}

0 commit comments

Comments
 (0)