Get join_buffer_for_channel compiling
Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
parent
364ed1f840
commit
71611ee7a2
6 changed files with 73 additions and 65 deletions
|
@ -3,9 +3,13 @@ use crate::test_both_dbs;
|
|||
use language::proto;
|
||||
use text::Buffer;
|
||||
|
||||
test_both_dbs!(test_buffers, test_buffers_postgres, test_buffers_sqlite);
|
||||
test_both_dbs!(
|
||||
test_channel_buffers,
|
||||
test_channel_buffers_postgres,
|
||||
test_channel_buffers_sqlite
|
||||
);
|
||||
|
||||
async fn test_buffers(db: &Arc<Database>) {
|
||||
async fn test_channel_buffers(db: &Arc<Database>) {
|
||||
// Prep database test info
|
||||
let a_id = db
|
||||
.create_user(
|
||||
|
@ -48,6 +52,8 @@ async fn test_buffers(db: &Arc<Database>) {
|
|||
.unwrap()
|
||||
.user_id;
|
||||
|
||||
let owner_id = db.create_server("production").await.unwrap().0 as u32;
|
||||
|
||||
let zed_id = db.create_root_channel("zed", "1", a_id).await.unwrap();
|
||||
|
||||
db.invite_channel_member(zed_id, b_id, a_id, false)
|
||||
|
@ -58,16 +64,19 @@ async fn test_buffers(db: &Arc<Database>) {
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
// TODO: Join buffer
|
||||
let buffer_id = db.get_or_create_buffer_for_channel(zed_id);
|
||||
let buffer_response_a = db
|
||||
.join_buffer_for_channel(zed_id, a_id, ConnectionId { owner_id, id: 1 })
|
||||
.await
|
||||
.unwrap();
|
||||
let buffer_id = BufferId::from_proto(buffer_response_a.buffer_id);
|
||||
|
||||
let mut buffer = Buffer::new(0, 0, "".to_string());
|
||||
let mut buffer_a = Buffer::new(0, 0, "".to_string());
|
||||
let mut operations = Vec::new();
|
||||
operations.push(buffer.edit([(0..0, "hello world")]));
|
||||
operations.push(buffer.edit([(5..5, ", cruel")]));
|
||||
operations.push(buffer.edit([(0..5, "goodbye")]));
|
||||
operations.push(buffer.undo().unwrap().1);
|
||||
assert_eq!(buffer.text(), "hello, cruel world");
|
||||
operations.push(buffer_a.edit([(0..0, "hello world")]));
|
||||
operations.push(buffer_a.edit([(5..5, ", cruel")]));
|
||||
operations.push(buffer_a.edit([(0..5, "goodbye")]));
|
||||
operations.push(buffer_a.undo().unwrap().1);
|
||||
assert_eq!(buffer_a.text(), "hello, cruel world");
|
||||
|
||||
let operations = operations
|
||||
.into_iter()
|
||||
|
@ -76,11 +85,14 @@ async fn test_buffers(db: &Arc<Database>) {
|
|||
|
||||
db.update_buffer(buffer_id, &operations).await.unwrap();
|
||||
|
||||
let buffer_data = db.open_buffer(buffer_id).await.unwrap();
|
||||
let buffer_response_b = db
|
||||
.join_buffer_for_channel(zed_id, b_id, ConnectionId { owner_id, id: 2 })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let mut buffer_2 = Buffer::new(0, 0, buffer_data.base_text);
|
||||
buffer_2
|
||||
.apply_ops(buffer_data.operations.into_iter().map(|operation| {
|
||||
let mut buffer_b = Buffer::new(0, 0, buffer_response_b.base_text);
|
||||
buffer_b
|
||||
.apply_ops(buffer_response_b.operations.into_iter().map(|operation| {
|
||||
let operation = proto::deserialize_operation(operation).unwrap();
|
||||
if let language::Operation::Buffer(operation) = operation {
|
||||
operation
|
||||
|
@ -90,5 +102,30 @@ async fn test_buffers(db: &Arc<Database>) {
|
|||
}))
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(buffer_2.text(), "hello, cruel world");
|
||||
assert_eq!(buffer_b.text(), "hello, cruel world");
|
||||
|
||||
// Ensure that C fails to open the buffer
|
||||
assert!(db
|
||||
.join_buffer_for_channel(zed_id, c_id, ConnectionId { owner_id, id: 3 })
|
||||
.await
|
||||
.is_err());
|
||||
|
||||
//Ensure that both collaborators have shown up
|
||||
assert_eq!(
|
||||
buffer_response_b.collaborators,
|
||||
&[
|
||||
rpc::proto::Collaborator {
|
||||
user_id: a_id.to_proto(),
|
||||
peer_id: Some(rpc::proto::PeerId { id: 1, owner_id }),
|
||||
replica_id: 0,
|
||||
},
|
||||
rpc::proto::Collaborator {
|
||||
user_id: b_id.to_proto(),
|
||||
peer_id: Some(rpc::proto::PeerId { id: 2, owner_id }),
|
||||
replica_id: 1,
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
// Leave buffer
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue