Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Fix test (+ introduce some additional test cases)
Browse files Browse the repository at this point in the history
  • Loading branch information
bfollington committed Feb 14, 2024
1 parent 67ecd9a commit c901d07
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions xcode/Subconscious/SubconsciousTests/Tests_UserLikesService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,40 @@ final class Tests_UserLikesService: XCTestCase {
XCTAssert(likes2.count == 1)
}

func testDuplicateLikes() async throws {
let tmp = try TestUtilities.createTmpDir()
let data = try await TestUtilities.createDataServiceEnvironment(tmp: tmp)

let likes = try await data.userLikes.readOurLikes()

XCTAssert(likes.isEmpty)

try await data.userLikes.persistLike(for: Slashlink("@ben/lmao")!)
try await data.userLikes.persistLike(for: Slashlink("@ben/lmao")!)

let likes2 = try await data.userLikes.readOurLikes()

XCTAssert(likes2.count == 1)
}

func testDeduplicateDuringParsing() async throws {
let tmp = try TestUtilities.createTmpDir()
let data = try await TestUtilities.createDataServiceEnvironment(tmp: tmp)

try await data.userLikes.writeOurLikes(
likes: UserLikesEntry(
collection: [
Slashlink("@ben/lmao")!,
Slashlink("@ben/lmao")!,
Slashlink("@ben/lmao")!
]
)
)

let likes = try await data.userLikes.readOurLikes()
XCTAssert(likes.count == 1)
}

func testRemoveLike() async throws {
let tmp = try TestUtilities.createTmpDir()
let data = try await TestUtilities.createDataServiceEnvironment(tmp: tmp)
Expand All @@ -43,7 +77,7 @@ final class Tests_UserLikesService: XCTestCase {

try await data.userLikes.persistLike(for: Slashlink("@ben/test")!)
try await data.userLikes.persistLike(for: Slashlink("@ben/lmao")!)
try await data.userLikes.persistLike(for: Slashlink("@ben/lmao")!)
try await data.userLikes.persistLike(for: Slashlink("@ben/another")!)

let likes2 = try await data.userLikes.readOurLikes()

Expand All @@ -66,7 +100,7 @@ final class Tests_UserLikesService: XCTestCase {

try await data.userLikes.persistLike(for: Slashlink("@ben/test")!)
try await data.userLikes.persistLike(for: Slashlink("@ben/lmao")!)
try await data.userLikes.persistLike(for: Slashlink("@ben/lmao")!)
try await data.userLikes.persistLike(for: Slashlink("@ben/another")!)

let liked = try await data.userLikes.isLikedByUs(address: Slashlink("@ben/lmao")!)

Expand Down

0 comments on commit c901d07

Please sign in to comment.