krz/keycask

Password manager: Swift core library, CLI for macOS/Linux/Windows, iOS/macOS app. cli password-manager swift

Tests/KeycaskCoreTests/EntryTests.swift

40 lines · 1418 bytes

 1import Foundation
 2import Testing
 3
 4@testable import KeycaskCore
 5
 6@Suite struct EntryTests {
 7    @Test func initNormalizesTagsAndTruncatesDates() {
 8        let now = Date(timeIntervalSince1970: 1_700_000_000.75)
 9        let e = Entry(
10            name: "gh", password: "p", tags: [" work", "Dev", "dev", "", "alpha"], now: now)
11        #expect(e.tags == ["alpha", "Dev", "work"])
12        #expect(e.created == Date(timeIntervalSince1970: 1_700_000_000))
13        #expect(e.updated == e.created)
14    }
15
16    @Test func normalizeSortsCaseInsensitivelyAndKeepsFirstSpelling() {
17        #expect(Entry.normalize(tags: ["b", "A", "a", "B"]) == ["A", "b"])
18        #expect(Entry.normalize(tags: []) == [])
19    }
20
21    @Test func hasTagIsCaseInsensitive() {
22        let e = Entry(name: "gh", password: "p", tags: ["Dev"])
23        #expect(e.hasTag("dev"))
24        #expect(e.hasTag("DEV"))
25        #expect(!e.hasTag("ops"))
26    }
27
28    @Test func matchesSearchesEveryTextFieldExceptPassword() {
29        let e = Entry(
30            name: "GitHub", username: "cmc", password: "hunter2", url: "https://github.com",
31            notes: "downtown office", tags: ["Dev"])
32        #expect(e.matches("github"))
33        #expect(e.matches("CMC"))
34        #expect(e.matches("github.com"))
35        #expect(e.matches("downtown"))
36        #expect(e.matches("dev"))
37        #expect(!e.matches("hunter2"))
38        #expect(!e.matches("nothing"))
39    }
40}