Skip to content
This repository was archived by the owner on Sep 21, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,22 @@ impl DB {
Ok(res)
}

/// Tries to increase update serial number.
///
/// Returns the next serial number that should be used
/// for the next update.
///
/// If the bot is not configured yet, always returns 1.
pub async fn increase_get_serial(&self) -> anyhow::Result<usize> {
let serial = self.get_last_serial().await?;
let _serial: Option<SerialReps> = self
.db
.update(("config", "config"))
.merge(json!({ "serial": serial + 1 }))
.await?;
Ok(serial + 1)
if let Some(config) = self.get_config().await? {
let serial = config.serial + 1;
let config = BotConfig { serial, ..config };
self.set_config(&config).await?;
Ok(serial)
} else {
// Bot is not configured yet.
Ok(1)
}
}

// TODO: take string as resource id
Expand Down
20 changes: 16 additions & 4 deletions tests/test_something.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,19 @@ def test_update(acfactory, storebot):

def test_import(acfactory, storebot_example):
"""Test that import works."""
# Do nothing except for initializing `storebot_example` fixture.
# If the test started, it means the bot
# with imported apps has been created successfuly.
pass
(ac1,) = acfactory.get_online_accounts(1)

bot_contact = ac1.create_contact(storebot_example.addr)
bot_chat = bot_contact.create_chat()
bot_chat.send_text("hi!")

msg_in = ac1.wait_next_incoming_message()
ac1._evtracker.get_matching("DC_EVENT_WEBXDC_STATUS_UPDATE")
assert msg_in.text == "Welcome to the appstore bot!"

assert msg_in.is_webxdc()
status_updates = msg_in.get_status_updates()
assert len(status_updates) == 1
payload = status_updates[0]["payload"]
app_infos = payload["app_infos"]
assert len(app_infos) == 4