Add lookupAccountByHandle
This commit is contained in:
parent
2a6154b5ec
commit
ab471020b7
1 changed files with 23 additions and 0 deletions
23
src/db.zig
23
src/db.zig
|
@ -91,6 +91,14 @@ pub const MemoryDb = struct {
|
|||
|
||||
return acc;
|
||||
}
|
||||
|
||||
pub fn lookupAccountByHandle(self: *Self, handle: []const u8) !?Account {
|
||||
for (self.accounts.items) |a| {
|
||||
if (ciutf8.eql(handle, a.handle)) return a;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
test "createAccount" {
|
||||
|
@ -118,3 +126,18 @@ test "createAccount" {
|
|||
next_id.val = admin_id;
|
||||
try std.testing.expectError(error.DuplicateId, db.createAccount("jaina"));
|
||||
}
|
||||
|
||||
test "lookupAccountByHandle" {
|
||||
var next_id = ConstId{};
|
||||
var db = MemoryDb.init(std.testing.allocator, next_id.source());
|
||||
defer db.deinit();
|
||||
|
||||
const admin_id = try Uuid.parse("00000000-ffff-0000-0000-000000000000");
|
||||
const sally_id = try Uuid.parse("00000000-eeee-0000-0000-000000000000");
|
||||
|
||||
next_id.val = admin_id;
|
||||
_ = try db.createAccount("admin");
|
||||
|
||||
next_id.val = sally_id;
|
||||
_ = try db.createAccount("sally");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue