feat: codegen script to gen identiy aggregate tests
This commit is contained in:
parent
f083a40395
commit
b9536fd15d
1 changed files with 149 additions and 0 deletions
149
utils/gen_cmd_event_inits.sh
Executable file
149
utils/gen_cmd_event_inits.sh
Executable file
|
@ -0,0 +1,149 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
help() {
|
||||||
|
echo "Usage: gen_cmd_event_inits.sh
|
||||||
|
<domain name>
|
||||||
|
<service name>
|
||||||
|
<cmd struct name>
|
||||||
|
<event struct name>
|
||||||
|
|
||||||
|
<service struct name>
|
||||||
|
<service obj>
|
||||||
|
<service method>
|
||||||
|
<service use case>
|
||||||
|
"
|
||||||
|
}
|
||||||
|
|
||||||
|
run() {
|
||||||
|
echo "//service
|
||||||
|
use mockall::predicate::*;
|
||||||
|
use mockall::*;
|
||||||
|
#[automock]
|
||||||
|
|
||||||
|
// command
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
impl $3 {
|
||||||
|
pub fn get_cmd() -> Self {
|
||||||
|
Self {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// events
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use crate::$1::application::services::$2::command::$3;
|
||||||
|
|
||||||
|
impl $4 {
|
||||||
|
pub fn get_event(cmd: &${3}) -> Self {
|
||||||
|
Self {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// service
|
||||||
|
|
||||||
|
impl $5 {
|
||||||
|
pub fn mock_service(
|
||||||
|
times: Option<usize>,
|
||||||
|
cmd: command::$3,
|
||||||
|
) -> $6 {
|
||||||
|
let mut m = Mock${8}::default();
|
||||||
|
let res = events::$4::get_event(&cmd);
|
||||||
|
|
||||||
|
if let Some(times) = times {
|
||||||
|
m.expect_${7}().times(times).return_const(Ok(res));
|
||||||
|
} else {
|
||||||
|
m.expect_${7}().return_const(Ok(res));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sync::Arc::new(m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// aggregate test
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_user_aggregate_${2}() {
|
||||||
|
use crate::${1}::application::services::${2}::{*, service::*, command::*, events::*};
|
||||||
|
|
||||||
|
let cmd = ${3}::get_cmd();
|
||||||
|
let expected = ${4}::get_event(&cmd);
|
||||||
|
let expected = IdentityEvent::$(echo $4 | sed 's/Event//')(expected);
|
||||||
|
|
||||||
|
let mut services = MockIdentityServicesInterface::new();
|
||||||
|
services
|
||||||
|
.expect_${2}()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.return_const(${5}::mock_service(
|
||||||
|
IS_CALLED_ONLY_ONCE,
|
||||||
|
cmd.clone(),
|
||||||
|
));
|
||||||
|
|
||||||
|
UserTestFramework::with(Arc::new(services))
|
||||||
|
.given_no_previous_events()
|
||||||
|
.when(IdentityCommand::$(echo $3 | sed 's/Command//')(cmd))
|
||||||
|
.then_expect_events(vec![expected]);
|
||||||
|
}
|
||||||
|
|
||||||
|
"
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
# echo "Usage: gen_cmd_event_inits.sh
|
||||||
|
# <domain name>
|
||||||
|
# <service name>
|
||||||
|
# <cmd struct name>
|
||||||
|
# <event struct name>
|
||||||
|
#
|
||||||
|
# <service struct name>
|
||||||
|
# <service obj>
|
||||||
|
# <service method>
|
||||||
|
|
||||||
|
|
||||||
|
if [ -z $1 ]
|
||||||
|
then
|
||||||
|
help
|
||||||
|
elif [ -z $2 ]
|
||||||
|
then
|
||||||
|
help
|
||||||
|
elif [ -z $3 ]
|
||||||
|
then
|
||||||
|
help
|
||||||
|
|
||||||
|
elif [ -z $4 ]
|
||||||
|
then
|
||||||
|
help
|
||||||
|
|
||||||
|
elif [ -z $5 ]
|
||||||
|
then
|
||||||
|
help
|
||||||
|
|
||||||
|
elif [ -z $6 ]
|
||||||
|
then
|
||||||
|
help
|
||||||
|
|
||||||
|
elif [ -z $7 ]
|
||||||
|
then
|
||||||
|
help
|
||||||
|
|
||||||
|
elif [ -z $8 ]
|
||||||
|
then
|
||||||
|
help
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
else
|
||||||
|
run "${@}"
|
||||||
|
run "${@}" | wl-copy
|
||||||
|
fi
|
Loading…
Reference in a new issue