-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BITAU-136] Sync Failure Message (#193)
- Loading branch information
1 parent
94fed8c
commit 309d296
Showing
15 changed files
with
297 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,30 +207,25 @@ class AuthenticatorItemRepositoryTests: AuthenticatorTestCase { // swiftlint:dis | |
let item = ItemListItem.fixture() | ||
let sharedItem = ItemListItem.fixtureShared() | ||
|
||
let result = try await subject.refreshTotpCodes(on: [item, sharedItem]) | ||
let result = try await subject.refreshTotpCodes(on: [item, sharedItem, .syncError()]) | ||
let actual = try XCTUnwrap(result[0]) | ||
|
||
XCTAssertEqual(actual.id, item.id) | ||
XCTAssertEqual(actual.name, item.name) | ||
XCTAssertEqual(actual.accountName, item.accountName) | ||
switch actual.itemType { | ||
case .sharedTotp: | ||
XCTFail("Shared TOTP itemType found when expecting TOTP") | ||
case let .totp(model): | ||
XCTAssertEqual(model.totpCode, newCodeModel) | ||
} | ||
XCTAssertEqual(actual.totpCodeModel, newCodeModel) | ||
|
||
let shared = try XCTUnwrap(result[1]) | ||
|
||
XCTAssertEqual(shared.id, sharedItem.id) | ||
XCTAssertEqual(shared.name, sharedItem.name) | ||
XCTAssertEqual(shared.accountName, sharedItem.accountName) | ||
switch shared.itemType { | ||
case let .sharedTotp(model): | ||
XCTAssertEqual(model.totpCode, newCodeModel) | ||
case .totp: | ||
XCTFail("TOTP itemType found when expecting Shared TOTP") | ||
} | ||
XCTAssertEqual(shared.totpCodeModel, newCodeModel) | ||
|
||
let syncError = try XCTUnwrap(result[2]) | ||
XCTAssertEqual(syncError, ItemListItem.syncError()) | ||
|
||
XCTAssertTrue(errorReporter.errors.isEmpty) | ||
} | ||
|
||
/// `saveTemporarySharedItem(_)` saves a temporary item into the Authenticator Bridge shared store. | ||
|
@@ -387,6 +382,44 @@ class AuthenticatorItemRepositoryTests: AuthenticatorTestCase { // swiftlint:dis | |
) | ||
} | ||
|
||
/// `itemListPublisher()` returns a favorites section and a local codes section as normal. Adds a syncError section | ||
/// when the sync process if throwing an error. | ||
func test_itemListPublisher_syncError() async throws { | ||
configService.featureFlagsBool[.enablePasswordManagerSync] = true | ||
sharedItemService.syncOn = true | ||
let items = [ | ||
AuthenticatorItem.fixture(id: "1", name: "One"), | ||
AuthenticatorItem.fixture(favorite: true, id: "2", name: "Two"), | ||
] | ||
let sharedItem = AuthenticatorBridgeItemDataView.fixture(accountDomain: "Domain", | ||
accountEmail: "[email protected]", | ||
totpKey: "totpKey") | ||
sharedItemService.storedItems = ["userId": [sharedItem]] | ||
let unorganizedItem = itemListItem(from: items[0]) | ||
let favoritedItem = itemListItem(from: items[1]) | ||
|
||
authItemService.authenticatorItemsSubject.send(items) | ||
sharedItemService.sharedItemsSubject.send(completion: .failure(AuthenticatorTestError.example)) | ||
|
||
var iterator = try await subject.itemListPublisher().makeAsyncIterator() | ||
let sections = try await iterator.next() | ||
|
||
XCTAssertEqual( | ||
sections, | ||
[ | ||
ItemListSection(id: "Favorites", | ||
items: [favoritedItem], | ||
name: Localizations.favorites), | ||
ItemListSection(id: "LocalCodes", | ||
items: [unorganizedItem], | ||
name: Localizations.localCodes), | ||
ItemListSection(id: "SyncError", | ||
items: [.syncError()], | ||
name: ""), | ||
] | ||
) | ||
} | ||
|
||
/// `itemListPublisher()` returns a favorites section as before, when the feature flag is enabled, but | ||
/// the user has not yet enabled sync. | ||
func test_itemListPublisher_syncOff() async throws { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
AuthenticatorShared/UI/Vault/ItemList/ItemList/ItemListItemTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import XCTest | ||
|
||
@testable import AuthenticatorShared | ||
|
||
// MARK: - ItemListItemTests | ||
|
||
class ItemListItemTests: AuthenticatorTestCase { | ||
var subject: ItemListItem! | ||
|
||
/// `totpCodeModel` returns the associated `TOTPCodeModel` for an item of type `.sharedTotp`. | ||
func test_totpCodeModel_shared() { | ||
let expected = TOTPCodeModel(code: "098765", codeGenerationDate: .now, period: 30) | ||
subject = .fixtureShared(totp: .fixture(totpCode: expected)) | ||
|
||
XCTAssertEqual(expected, subject.totpCodeModel) | ||
} | ||
|
||
/// `totpCodeModel` returns `nil` for an item of type `.syncError`. | ||
func test_totpCodeModel_syncError() { | ||
subject = .syncError() | ||
|
||
XCTAssertNil(subject.totpCodeModel) | ||
} | ||
|
||
/// `totpCodeModel` returns the associated `TOTPCodeModel` for an item of type `.totp`. | ||
func test_totpCodeModel_totp() { | ||
let expected = TOTPCodeModel(code: "098765", codeGenerationDate: .now, period: 30) | ||
subject = .fixture(totp: .fixture(totpCode: expected)) | ||
|
||
XCTAssertEqual(expected, subject.totpCodeModel) | ||
} | ||
|
||
/// For the `.sharedTotp` case, `with(newTotpModel:)` returns a copy of the item with the new TOTP code. | ||
func test_withNewTotpModel_shared() { | ||
subject = .fixtureShared() | ||
let newModel = TOTPCodeModel( | ||
code: "098765", | ||
codeGenerationDate: Date(), | ||
period: 30 | ||
) | ||
|
||
let newItem = subject.with(newTotpModel: newModel) | ||
XCTAssertEqual(newItem.totpCodeModel, newModel) | ||
} | ||
|
||
/// For the `.syncError` case, `with(newTotpModel:)` simply returns a copy of the item. | ||
func test_withNewTotpModel_syncError() { | ||
subject = .syncError() | ||
let newModel = TOTPCodeModel( | ||
code: "098765", | ||
codeGenerationDate: Date(), | ||
period: 30 | ||
) | ||
|
||
let newItem = subject.with(newTotpModel: newModel) | ||
XCTAssertEqual(subject, newItem) | ||
} | ||
|
||
/// For the `.totp`case, `with(newTotpModel:)` returns a copy of the item with the new TOTP code. | ||
func test_withNewTotpModel_totp() { | ||
subject = .fixture() | ||
let newModel = TOTPCodeModel( | ||
code: "098765", | ||
codeGenerationDate: Date(), | ||
period: 30 | ||
) | ||
|
||
let newItem = subject.with(newTotpModel: newModel) | ||
XCTAssertEqual(newItem.totpCodeModel, newModel) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.