Skip to content

Commit

Permalink
fix: add unit tests for update verb builder isEncrypted
Browse files Browse the repository at this point in the history
  • Loading branch information
murali-shris committed Sep 12, 2024
1 parent 4affdfd commit 141716a
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions packages/at_commons/test/update_verb_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -523,4 +523,79 @@ void main() {
});
});
});
group('A group of tests to validate isEncrypted flag in update verb builder',
() {
test('for public key isEncrypted is false', () {
var updateBuilder = UpdateVerbBuilder()
..value = '[email protected]'
..atKey.metadata.isPublic = true
..atKey.metadata.ttl = 5000
..atKey.key = 'email'
..atKey.sharedBy = '@alice';
var updateCommand = updateBuilder.buildCommand();
expect(updateCommand,
'update:ttl:5000:public:email@alice [email protected]\n');
var updateVerbParams =
getVerbParams(VerbSyntax.update, updateCommand.trim());
print(updateVerbParams);
// existing behaviour. TODO change to false after changes for update verb isEncrypted flag
expect(updateVerbParams['isEncrypted'], null);
});
test('for shared key - isEncrypted is true if set in metadata', () {
var updateBuilder = UpdateVerbBuilder()
..value = 'sampleEncryptedValue'
..atKey.metadata.ttl = 5000
..atKey.metadata.isEncrypted = true
..atKey.key = 'email'
..atKey.sharedBy = '@alice'
..atKey.sharedWith = '@bob';
var updateCommand = updateBuilder.buildCommand();
print(updateCommand);
expect(updateCommand,
'update:ttl:5000:isEncrypted:true:@bob:email@alice sampleEncryptedValue\n');
var updateVerbParams =
getVerbParams(VerbSyntax.update, updateCommand.trim());
print(updateVerbParams);
expect(updateVerbParams['isEncrypted'], 'true');
});
test('for shared key - isEncrypted is false if NOT set in metadata', () {
var updateBuilder = UpdateVerbBuilder()
..value = 'sampleEncryptedValue'
..atKey.metadata.ttl = 5000
..atKey.key = 'email'
..atKey.sharedBy = '@alice'
..atKey.sharedWith = '@bob';
var updateCommand = updateBuilder.buildCommand();
print(updateCommand);
// existing behaviour. TODO Should contain isEncrypted:false after changes for update verb isEncrypted flag
expect(updateCommand,
'update:ttl:5000:@bob:email@alice sampleEncryptedValue\n');
var updateVerbParams =
getVerbParams(VerbSyntax.update, updateCommand.trim());
print(updateVerbParams);
// existing behaviour. TODO Should be false after changes for update verb isEncrypted flag
expect(updateVerbParams['isEncrypted'], null);
});

test('for shared key - isEncrypted is false if set to false in metadata',
() {
var updateBuilder = UpdateVerbBuilder()
..value = 'sampleEncryptedValue'
..atKey.metadata.ttl = 5000
..atKey.metadata.isEncrypted = false
..atKey.key = 'email'
..atKey.sharedBy = '@alice'
..atKey.sharedWith = '@bob';
var updateCommand = updateBuilder.buildCommand();
print(updateCommand);
// existing behaviour. TODO Should contain isEncrypted:false after changes for update verb isEncrypted flag
expect(updateCommand,
'update:ttl:5000:@bob:email@alice sampleEncryptedValue\n');
var updateVerbParams =
getVerbParams(VerbSyntax.update, updateCommand.trim());
print(updateVerbParams);
// existing behaviour. TODO Should be false after changes for update verb isEncrypted flag
expect(updateVerbParams['isEncrypted'], null);
});
});
}

0 comments on commit 141716a

Please sign in to comment.