Skip to content

Commit

Permalink
fix: remove default tag (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
igamigo authored May 16, 2024
1 parent e889c49 commit 93967f8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/store/sqlite_store/store.sql
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ CREATE TABLE state_sync (

-- insert initial row into state_sync table
INSERT OR IGNORE INTO state_sync (block_num, tags)
SELECT 0, '[0]'
SELECT 0, '[]'
WHERE (
SELECT COUNT(*) FROM state_sync
) = 0;
Expand Down
21 changes: 10 additions & 11 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,36 +326,35 @@ async fn test_tags() {
let mut client = create_test_client();

// Assert that the store gets created with the tag 0 (used for notes consumable by any account)
let tag_1: NoteTag = 0.into();
assert_eq!(client.get_note_tags().unwrap(), vec![tag_1]);
assert_eq!(client.get_note_tags().unwrap(), vec![]);

// add a tag
let tag_2: NoteTag = 1.into();
let tag_3: NoteTag = 2.into();
let tag_1: NoteTag = 1.into();
let tag_2: NoteTag = 2.into();
client.add_note_tag(tag_1).unwrap();
client.add_note_tag(tag_2).unwrap();
client.add_note_tag(tag_3).unwrap();

// verify that the tag is being tracked
assert_eq!(client.get_note_tags().unwrap(), vec![tag_1, tag_2, tag_3]);
assert_eq!(client.get_note_tags().unwrap(), vec![tag_1, tag_2]);

// attempt to add the same tag again
client.add_note_tag(tag_1).unwrap();

// verify that the tag is still being tracked only once
assert_eq!(client.get_note_tags().unwrap(), vec![tag_1, tag_2, tag_3]);
assert_eq!(client.get_note_tags().unwrap(), vec![tag_1, tag_2]);

// Try removing non-existent tag
let tag_4: NoteTag = 4.into();
client.remove_note_tag(tag_4).unwrap();

// verify that the tracked tags are unchanged
assert_eq!(client.get_note_tags().unwrap(), vec![tag_1, tag_2, tag_3]);
assert_eq!(client.get_note_tags().unwrap(), vec![tag_1, tag_2]);

// remove second tag
client.remove_note_tag(tag_2).unwrap();
client.remove_note_tag(tag_1).unwrap();

// verify that tag_2 is not tracked anymore
assert_eq!(client.get_note_tags().unwrap(), vec![tag_1, tag_3]);
// verify that tag_1 is not tracked anymore
assert_eq!(client.get_note_tags().unwrap(), vec![tag_2]);
}

#[tokio::test]
Expand Down

0 comments on commit 93967f8

Please sign in to comment.