|
| 1 | +import 'package:gotrue/src/types/user_attributes.dart'; |
| 2 | +import 'package:test/test.dart'; |
| 3 | + |
| 4 | +void main() { |
| 5 | + late String email; |
| 6 | + late String phone; |
| 7 | + late String password; |
| 8 | + late String nonce; |
| 9 | + late Map<String, dynamic> data; |
| 10 | + |
| 11 | + setUp(() { |
| 12 | + email = 'john@supabase.com'; |
| 13 | + phone = '+1234567890'; |
| 14 | + password = 'password'; |
| 15 | + nonce = 'nonce'; |
| 16 | + data = {'first_name': 'John', 'last_name': 'Doe'}; |
| 17 | + }); |
| 18 | + |
| 19 | + group('User attributes', () { |
| 20 | + late UserAttributes userAttributesOne; |
| 21 | + late UserAttributes userAttributesTwo; |
| 22 | + |
| 23 | + setUp(() { |
| 24 | + userAttributesOne = UserAttributes( |
| 25 | + email: email, |
| 26 | + phone: phone, |
| 27 | + password: password, |
| 28 | + nonce: nonce, |
| 29 | + data: data, |
| 30 | + ); |
| 31 | + |
| 32 | + userAttributesTwo = UserAttributes( |
| 33 | + email: email, |
| 34 | + phone: phone, |
| 35 | + password: password, |
| 36 | + nonce: nonce, |
| 37 | + data: data, |
| 38 | + ); |
| 39 | + }); |
| 40 | + |
| 41 | + test('Attributes are equals', () { |
| 42 | + // assert |
| 43 | + expect(userAttributesOne, equals(userAttributesTwo)); |
| 44 | + }); |
| 45 | + |
| 46 | + test('Attributes are not equals', () { |
| 47 | + // arrange |
| 48 | + final userAttributesThree = UserAttributes( |
| 49 | + email: 'email', |
| 50 | + phone: phone, |
| 51 | + password: password, |
| 52 | + nonce: nonce, |
| 53 | + data: {'first_name': 'Jane', 'last_name': 'Doe'}, |
| 54 | + ); |
| 55 | + |
| 56 | + // assert |
| 57 | + expect(userAttributesOne, isNot(equals(userAttributesThree))); |
| 58 | + }); |
| 59 | + }); |
| 60 | + |
| 61 | + group('Admin user attributes', () { |
| 62 | + late AdminUserAttributes adminUserAttributesOne; |
| 63 | + late AdminUserAttributes adminUserAttributesTwo; |
| 64 | + |
| 65 | + late Map<String, dynamic> userMetadata; |
| 66 | + late Map<String, dynamic> appMetadata; |
| 67 | + late bool emailConfirm; |
| 68 | + late bool phoneConfirm; |
| 69 | + late String banDuration; |
| 70 | + |
| 71 | + setUp(() { |
| 72 | + userMetadata = {'first_name': 'John', 'last_name': 'Doe'}; |
| 73 | + appMetadata = { |
| 74 | + 'roles': ['admin'] |
| 75 | + }; |
| 76 | + emailConfirm = true; |
| 77 | + phoneConfirm = true; |
| 78 | + banDuration = '1d'; |
| 79 | + |
| 80 | + adminUserAttributesOne = AdminUserAttributes( |
| 81 | + email: email, |
| 82 | + phone: phone, |
| 83 | + password: password, |
| 84 | + data: data, |
| 85 | + userMetadata: userMetadata, |
| 86 | + appMetadata: appMetadata, |
| 87 | + emailConfirm: emailConfirm, |
| 88 | + phoneConfirm: phoneConfirm, |
| 89 | + banDuration: banDuration, |
| 90 | + ); |
| 91 | + |
| 92 | + adminUserAttributesTwo = AdminUserAttributes( |
| 93 | + email: email, |
| 94 | + phone: phone, |
| 95 | + password: password, |
| 96 | + data: data, |
| 97 | + userMetadata: userMetadata, |
| 98 | + appMetadata: appMetadata, |
| 99 | + emailConfirm: emailConfirm, |
| 100 | + phoneConfirm: phoneConfirm, |
| 101 | + banDuration: banDuration, |
| 102 | + ); |
| 103 | + }); |
| 104 | + |
| 105 | + test('Attributes are equals', () { |
| 106 | + // assert |
| 107 | + expect(adminUserAttributesOne, equals(adminUserAttributesTwo)); |
| 108 | + }); |
| 109 | + |
| 110 | + test('Attributes are not equals', () { |
| 111 | + // arrange |
| 112 | + final adminUserAttributesThree = AdminUserAttributes( |
| 113 | + email: email, |
| 114 | + phone: phone, |
| 115 | + password: password, |
| 116 | + data: data, |
| 117 | + userMetadata: {'first_name': 'Jane', 'last_name': 'Doe'}, |
| 118 | + appMetadata: appMetadata, |
| 119 | + emailConfirm: false, |
| 120 | + phoneConfirm: false, |
| 121 | + banDuration: 'banDuration', |
| 122 | + ); |
| 123 | + |
| 124 | + // assert |
| 125 | + expect(adminUserAttributesOne, isNot(equals(adminUserAttributesThree))); |
| 126 | + }); |
| 127 | + }); |
| 128 | +} |
0 commit comments