|
| 1 | +// Copyright 2026 The Chromium Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +@TestOn('browser') |
| 6 | +library; |
| 7 | + |
| 8 | +import 'dart:js_interop'; |
| 9 | +import 'dart:js_interop_unsafe'; |
| 10 | + |
| 11 | +import 'package:firebase_auth_web/src/interop/auth.dart' as auth_interop; |
| 12 | +import 'package:firebase_auth_web/src/interop/auth_interop.dart' |
| 13 | + as auth_js_interop; |
| 14 | +import 'package:flutter_test/flutter_test.dart'; |
| 15 | + |
| 16 | +void main() { |
| 17 | + group('User.toJson', () { |
| 18 | + test('converts JSObject from toJSON() to Map<String, dynamic>', () { |
| 19 | + final jsJson = JSObject() |
| 20 | + ..['uid'] = 'user-123'.toJS |
| 21 | + ..['email'] = 'user@example.com'.toJS |
| 22 | + ..['emailVerified'] = true.toJS; |
| 23 | + final jsUser = JSObject()..['toJSON'] = (() => jsJson).toJS; |
| 24 | + |
| 25 | + final user = auth_interop.User.getInstance( |
| 26 | + jsUser as auth_js_interop.UserJsImpl, |
| 27 | + )!; |
| 28 | + final json = user.toJson(); |
| 29 | + |
| 30 | + expect(json, isA<Map<String, dynamic>>()); |
| 31 | + expect( |
| 32 | + json, |
| 33 | + equals(<String, dynamic>{ |
| 34 | + 'uid': 'user-123', |
| 35 | + 'email': 'user@example.com', |
| 36 | + 'emailVerified': true, |
| 37 | + }), |
| 38 | + ); |
| 39 | + }); |
| 40 | + |
| 41 | + test('handles an empty JSObject from toJSON()', () { |
| 42 | + final emptyJson = JSObject(); |
| 43 | + final jsUser = JSObject()..['toJSON'] = (() => emptyJson).toJS; |
| 44 | + |
| 45 | + final user = auth_interop.User.getInstance( |
| 46 | + jsUser as auth_js_interop.UserJsImpl, |
| 47 | + )!; |
| 48 | + final json = user.toJson(); |
| 49 | + |
| 50 | + expect(json, isA<Map<String, dynamic>>()); |
| 51 | + expect(json, isEmpty); |
| 52 | + }); |
| 53 | + }); |
| 54 | +} |
0 commit comments