January 2019
Intermediate to advanced
520 pages
14h 32m
English
That's all, and now we have a crate that can be used to interact with a database. Since it's not binary, we need to guarantee that the code works correctly. It's a good practice to cover your code with tests, and we will do that now.
Add the following code to the lib.rs file:
#[cfg(test)]mod tests { use super::Api; #[test] fn create_users() { let api = Api::connect().unwrap(); let user_1 = api.register_user("user_1@example.com").unwrap(); let user_2 = api.register_user("user_2@example.com").unwrap(); let channel = api.create_channel(user_1.id, "My Channel", false).unwrap(); api.publish_channel(channel.id).unwrap(); api.add_member(channel.id, user_2.id).unwrap(); let message = api.add_message(channel.id, user_1.id, "Welcome!").unwrap(); ...Read now
Unlock full access