Skip to content

Commit bd8ee25

Browse files
author
Michael Sundqvist
committed
Add integration test
1 parent 9898201 commit bd8ee25

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright 2023, Google Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Threading.Tasks;
19+
using FirebaseAdmin.Auth;
20+
using Xunit;
21+
22+
namespace FirebaseAdmin.IntegrationTests.Auth
23+
{
24+
public class UpdateUserTest : IClassFixture<UpdateUserFixture>
25+
{
26+
private readonly UpdateUserFixture fixture;
27+
28+
public UpdateUserTest(UpdateUserFixture fixture)
29+
{
30+
this.fixture = fixture;
31+
}
32+
33+
[Fact]
34+
public async void CanUpdateProviderForUser()
35+
{
36+
var expectedProviderUid = $"google_{this.fixture.TestUser.Uid}";
37+
const string expectedProviderId = "google.com";
38+
const string expectedDisplayName = "Test";
39+
const string expectedEmail = "[email protected]";
40+
const string expectedPhone = "+11234567890";
41+
const string expectedPhotoUrl = "https://www.example.com/image.png";
42+
43+
var userRecordArgs = new UserRecordArgs
44+
{
45+
Uid = this.fixture.TestUser.Uid,
46+
ProviderToLink = new ProviderUserInfoArgs
47+
{
48+
Uid = expectedProviderUid,
49+
ProviderId = expectedProviderId,
50+
DisplayName = expectedDisplayName,
51+
Email = expectedEmail,
52+
PhoneNumber = expectedPhone,
53+
PhotoUrl = expectedPhotoUrl,
54+
},
55+
};
56+
57+
await FirebaseAuth.DefaultInstance.UpdateUserAsync(userRecordArgs);
58+
59+
var userRecord = await FirebaseAuth.DefaultInstance.GetUserAsync(this.fixture.TestUser.Uid);
60+
61+
Assert.Single(userRecord.ProviderData);
62+
var provider = userRecord.ProviderData.Single();
63+
64+
Assert.Equal(expectedProviderUid, provider.Uid);
65+
Assert.Equal(expectedProviderId, provider.ProviderId);
66+
Assert.Equal(expectedEmail, provider.Email);
67+
Assert.Equal(expectedPhone, provider.PhoneNumber);
68+
Assert.Equal(expectedPhotoUrl, provider.PhotoUrl);
69+
}
70+
}
71+
72+
public class UpdateUserFixture : IDisposable
73+
{
74+
private readonly TemporaryUserBuilder userBuilder;
75+
76+
public UpdateUserFixture()
77+
{
78+
IntegrationTestUtils.EnsureDefaultApp();
79+
this.userBuilder = new TemporaryUserBuilder(FirebaseAuth.DefaultInstance);
80+
this.TestUser = this.userBuilder.CreateRandomUserAsync().Result;
81+
this.ImportUserUid = this.ImportUserAsync().Result;
82+
}
83+
84+
public UserRecord TestUser { get; }
85+
86+
public string ImportUserUid { get; }
87+
88+
public void Dispose()
89+
{
90+
this.userBuilder.Dispose();
91+
}
92+
93+
private async Task<string> ImportUserAsync()
94+
{
95+
var randomArgs = TemporaryUserBuilder.RandomUserRecordArgs();
96+
var importUser = new ImportUserRecordArgs()
97+
{
98+
Uid = randomArgs.Uid,
99+
Email = randomArgs.Email,
100+
PhoneNumber = randomArgs.PhoneNumber,
101+
};
102+
103+
var result = await FirebaseAuth.DefaultInstance.ImportUsersAsync(
104+
new List<ImportUserRecordArgs>()
105+
{
106+
importUser,
107+
});
108+
Assert.Equal(1, result.SuccessCount);
109+
this.userBuilder.AddUid(randomArgs.Uid);
110+
return randomArgs.Uid;
111+
}
112+
}
113+
}

0 commit comments

Comments
 (0)