mirror of
https://github.com/SkyfallWasTaken/arcade-monitor.git
synced 2024-11-10 03:49:40 +00:00
Fix compilation, add tests
This commit is contained in:
parent
d377973c32
commit
4b0e3605f4
2 changed files with 61 additions and 2 deletions
|
@ -84,7 +84,7 @@ pub fn format_deleted_item(item: &ShopItem) -> String {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_slack_blocks(diffs: &Vec<String>) -> serde_json::Value {
|
||||
pub fn get_slack_body(diffs: &Vec<String>) -> serde_json::Value {
|
||||
let mut blocks_vec = vec![];
|
||||
for diff in diffs {
|
||||
blocks_vec.push(json!({
|
||||
|
@ -113,6 +113,64 @@ pub fn get_slack_blocks(diffs: &Vec<String>) -> serde_json::Value {
|
|||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod slack_tests {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn slack_body_is_correct() {
|
||||
let body = get_slack_body(&vec!["Test 1".into(), "Test 2".into(), "Test 3".into()]);
|
||||
assert_eq!(
|
||||
body,
|
||||
json!({
|
||||
"blocks": [
|
||||
{
|
||||
"type": "section",
|
||||
"text": {
|
||||
"type": "mrkdwn",
|
||||
"text": "Test 1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "divider"
|
||||
},
|
||||
{
|
||||
"type": "section",
|
||||
"text": {
|
||||
"type": "mrkdwn",
|
||||
"text": "Test 2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "divider"
|
||||
},
|
||||
{
|
||||
"type": "section",
|
||||
"text": {
|
||||
"type": "mrkdwn",
|
||||
"text": "Test 3"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "divider"
|
||||
},
|
||||
{
|
||||
"type": "context",
|
||||
"elements": [
|
||||
{
|
||||
"type": "mrkdwn",
|
||||
"text": format!("Arcade Monitor v{}", env!("CARGO_PKG_VERSION"))
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod format_new_tests {
|
||||
use super::*;
|
||||
|
@ -146,6 +204,7 @@ mod format_new_tests {
|
|||
mod diff_tests {
|
||||
use super::*;
|
||||
use indoc::indoc;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn price_diff() {
|
||||
|
|
|
@ -60,7 +60,7 @@ async fn run_scrape(env: Env) -> Result<String> {
|
|||
let changes = result.join("\n\n");
|
||||
|
||||
// slack webhook
|
||||
let slack_body = format::get_slack_blocks(&result);
|
||||
let slack_body = format::get_slack_body(&result);
|
||||
client
|
||||
.post(&slack_webhook_url)
|
||||
.body(slack_body.to_string())
|
||||
|
|
Loading…
Reference in a new issue