Skip to content

Commit f4f0232

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

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
var provider = userRecord.ProviderData.SingleOrDefault(x => x.ProviderId == expectedProviderId);
62+
63+
Assert.NotNull(provider);
64+
65+
Assert.Equal(expectedProviderUid, provider.Uid);
66+
Assert.Equal(expectedProviderId, provider.ProviderId);
67+
Assert.Equal(expectedEmail, provider.Email);
68+
// TODO: Apparently the accounts:update endpoint does not update the provider phone number even if
69+
// it is specified in the UpdateUserRequest.ProviderToLink object
70+
// Assert.Equal(expectedPhone, provider.PhoneNumber);
71+
Assert.Equal(expectedPhotoUrl, provider.PhotoUrl);
72+
}
73+
}
74+
75+
public class UpdateUserFixture : IDisposable
76+
{
77+
private readonly TemporaryUserBuilder userBuilder;
78+
79+
public UpdateUserFixture()
80+
{
81+
IntegrationTestUtils.EnsureDefaultApp();
82+
this.userBuilder = new TemporaryUserBuilder(FirebaseAuth.DefaultInstance);
83+
this.TestUser = this.userBuilder.CreateRandomUserAsync().Result;
84+
this.ImportUserUid = this.ImportUserAsync().Result;
85+
}
86+
87+
public UserRecord TestUser { get; }
88+
89+
public string ImportUserUid { get; }
90+
91+
public void Dispose()
92+
{
93+
this.userBuilder.Dispose();
94+
}
95+
96+
private async Task<string> ImportUserAsync()
97+
{
98+
var randomArgs = TemporaryUserBuilder.RandomUserRecordArgs();
99+
var importUser = new ImportUserRecordArgs()
100+
{
101+
Uid = randomArgs.Uid,
102+
Email = randomArgs.Email,
103+
PhoneNumber = randomArgs.PhoneNumber,
104+
};
105+
106+
var result = await FirebaseAuth.DefaultInstance.ImportUsersAsync(
107+
new List<ImportUserRecordArgs>()
108+
{
109+
importUser,
110+
});
111+
Assert.Equal(1, result.SuccessCount);
112+
this.userBuilder.AddUid(randomArgs.Uid);
113+
return randomArgs.Uid;
114+
}
115+
}
116+
}

0 commit comments

Comments
 (0)