Skip to content

Commit f3e44e7

Browse files
committed
fix(test): update taskchampion tests to match file-based storage
1 parent 7a62949 commit f3e44e7

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

test/utils/taskchampion/taskchampion_test.dart

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,34 @@ void main() {
2323
expect(controller.syncBackendUrlController.text, '');
2424
});
2525

26-
test('should load existing credentials', () async {
27-
SharedPreferences.setMockInitialValues({
28-
'encryptionSecret': 'mysecret',
29-
'clientId': 'client123',
30-
'syncBackendUrl': 'https://example.com',
31-
});
32-
26+
test('should load empty credentials when no credential files exist',
27+
() async {
28+
// CredentialsStorage reads from file system paths like:
29+
// ${base.path}/profiles/$profile/taskc_client_secret
30+
// ${base.path}/profiles/$profile/taskc_client_id
31+
// ${base.path}/profiles/$profile/backend_url_tc
32+
// In the test environment, these files do not exist, so all values
33+
// should return null and the controllers should remain empty.
3334
controller = ManageTaskChampionCredsController();
3435
await controller.loadCredentials();
35-
expect(controller.encryptionSecretController.text, 'mysecret');
36-
expect(controller.clientIdController.text, 'client123');
37-
expect(controller.syncBackendUrlController.text, 'https://example.com');
36+
37+
expect(controller.encryptionSecretController.text, '');
38+
expect(controller.clientIdController.text, '');
39+
expect(controller.syncBackendUrlController.text, '');
3840
});
3941

40-
test('should save credentials', () async {
42+
test('should attempt save and return error without network', () async {
43+
// saveCredentials() makes an HTTP request to verify credentials.
44+
// In the test environment there is no network, so it should return 1
45+
// (error) and not throw an unhandled exception.
4146
controller.encryptionSecretController.text = 'secret123';
4247
controller.clientIdController.text = 'clientABC';
4348
controller.syncBackendUrlController.text = 'https://backend.url';
4449

45-
await controller.saveCredentials();
46-
47-
final prefs = await SharedPreferences.getInstance();
50+
final result = await controller.saveCredentials();
4851

49-
expect(prefs.getString('encryptionSecret'), 'secret123');
50-
expect(prefs.getString('clientId'), 'clientABC');
51-
expect(prefs.getString('syncBackendUrl'), 'https://backend.url');
52+
// Returns 1 when the HTTP call fails (no network in test environment)
53+
expect(result, 1);
5254
});
5355
});
5456
}

0 commit comments

Comments
 (0)