Skip to content

Commit 840329c

Browse files
authored
chore: Split long user lifecycle test into multiple test cases (#241)
1 parent 7ea2974 commit 840329c

File tree

1 file changed

+83
-40
lines changed

1 file changed

+83
-40
lines changed

FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs

Lines changed: 83 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2020, 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+
115
using System;
216
using System.Collections.Generic;
317
using System.Linq;
@@ -14,9 +28,6 @@ namespace FirebaseAdmin.IntegrationTests.Auth
1428
public abstract class AbstractFirebaseAuthTest<T>
1529
where T : AbstractFirebaseAuth
1630
{
17-
private const string VerifyPasswordUrl =
18-
"https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword";
19-
2031
private const string ContinueUrl = "http://localhost/?a=1&b=2#c=3";
2132

2233
private static readonly ActionCodeSettings EmailLinkSettings = new ActionCodeSettings()
@@ -183,12 +194,11 @@ public async Task CreateUserWithParams()
183194
}
184195

185196
[Fact]
186-
public async Task UserLifecycle()
197+
public async Task CreateUser()
187198
{
188-
// Create user
189199
var user = await this.userBuilder.CreateUserAsync(new UserRecordArgs());
190-
var uid = user.Uid;
191200

201+
Assert.NotEmpty(user.Uid);
192202
Assert.Null(user.Email);
193203
Assert.Null(user.PhoneNumber);
194204
Assert.Null(user.DisplayName);
@@ -199,10 +209,16 @@ public async Task UserLifecycle()
199209
Assert.Null(user.UserMetaData.LastSignInTimestamp);
200210
Assert.Empty(user.ProviderData);
201211
Assert.Empty(user.CustomClaims);
212+
}
213+
214+
[Fact]
215+
public async Task GetUser()
216+
{
217+
var original = await this.userBuilder.CreateUserAsync(new UserRecordArgs());
202218

203-
// Get user by ID
204-
user = await this.Auth.GetUserAsync(uid);
205-
Assert.Equal(uid, user.Uid);
219+
var user = await this.Auth.GetUserAsync(original.Uid);
220+
221+
Assert.Equal(original.Uid, user.Uid);
206222
Assert.Null(user.Email);
207223
Assert.Null(user.PhoneNumber);
208224
Assert.Null(user.DisplayName);
@@ -213,63 +229,90 @@ public async Task UserLifecycle()
213229
Assert.Null(user.UserMetaData.LastSignInTimestamp);
214230
Assert.Empty(user.ProviderData);
215231
Assert.Empty(user.CustomClaims);
232+
}
216233

217-
// Update user
218-
var randomUser = TemporaryUserBuilder.RandomUserRecordArgs();
219-
var updateArgs = new UserRecordArgs()
220-
{
221-
Uid = uid,
222-
DisplayName = "Updated Name",
223-
Email = randomUser.Email,
224-
PhoneNumber = randomUser.PhoneNumber,
225-
PhotoUrl = "https://example.com/photo.png",
226-
EmailVerified = true,
227-
Password = "secret",
228-
};
229-
user = await this.Auth.UpdateUserAsync(updateArgs);
230-
Assert.Equal(uid, user.Uid);
231-
Assert.Equal(randomUser.Email, user.Email);
232-
Assert.Equal(randomUser.PhoneNumber, user.PhoneNumber);
233-
Assert.Equal("Updated Name", user.DisplayName);
234+
[Fact]
235+
public async Task UpdateUser()
236+
{
237+
var original = await this.userBuilder.CreateUserAsync(new UserRecordArgs());
238+
var updateArgs = TemporaryUserBuilder.RandomUserRecordArgs();
239+
updateArgs.Uid = original.Uid;
240+
updateArgs.EmailVerified = true;
241+
242+
var user = await this.Auth.UpdateUserAsync(updateArgs);
243+
244+
Assert.Equal(updateArgs.Uid, user.Uid);
245+
Assert.Equal(updateArgs.Email, user.Email);
246+
Assert.Equal(updateArgs.PhoneNumber, user.PhoneNumber);
247+
Assert.Equal("Random User", user.DisplayName);
234248
Assert.Equal("https://example.com/photo.png", user.PhotoUrl);
235249
Assert.True(user.EmailVerified);
236250
Assert.False(user.Disabled);
237251
Assert.NotNull(user.UserMetaData.CreationTimestamp);
238252
Assert.Null(user.UserMetaData.LastSignInTimestamp);
239253
Assert.Equal(2, user.ProviderData.Length);
240254
Assert.Empty(user.CustomClaims);
255+
}
256+
257+
[Fact]
258+
public async Task GetUserByEmail()
259+
{
260+
var original = await this.userBuilder.CreateRandomUserAsync();
241261

242-
// Get user by email
243-
user = await this.Auth.GetUserByEmailAsync(randomUser.Email);
244-
Assert.Equal(uid, user.Uid);
262+
var user = await this.Auth.GetUserByEmailAsync(original.Email);
245263

246-
// Disable user and remove properties
247-
var disableArgs = new UserRecordArgs()
264+
Assert.Equal(original.Uid, user.Uid);
265+
Assert.Equal(original.Email, user.Email);
266+
}
267+
268+
[Fact]
269+
public async Task GetUserByPhoneNumber()
270+
{
271+
var original = await this.userBuilder.CreateRandomUserAsync();
272+
273+
var user = await this.Auth.GetUserByPhoneNumberAsync(original.PhoneNumber);
274+
275+
Assert.Equal(original.Uid, user.Uid);
276+
Assert.Equal(original.PhoneNumber, user.PhoneNumber);
277+
}
278+
279+
[Fact]
280+
public async Task DisableUser()
281+
{
282+
var original = await this.userBuilder.CreateRandomUserAsync();
283+
284+
var disableArgs = new UserRecordArgs
248285
{
249-
Uid = uid,
286+
Uid = original.Uid,
250287
Disabled = true,
251288
DisplayName = null,
252289
PhoneNumber = null,
253290
PhotoUrl = null,
254291
};
255-
user = await this.Auth.UpdateUserAsync(disableArgs);
256-
Assert.Equal(uid, user.Uid);
257-
Assert.Equal(randomUser.Email, user.Email);
292+
var user = await this.Auth.UpdateUserAsync(disableArgs);
293+
294+
Assert.Equal(original.Uid, user.Uid);
295+
Assert.Equal(original.Email, user.Email);
258296
Assert.Null(user.PhoneNumber);
259297
Assert.Null(user.DisplayName);
260298
Assert.Null(user.PhotoUrl);
261-
Assert.True(user.EmailVerified);
299+
Assert.False(user.EmailVerified);
262300
Assert.True(user.Disabled);
263301
Assert.NotNull(user.UserMetaData.CreationTimestamp);
264302
Assert.Null(user.UserMetaData.LastSignInTimestamp);
265303
Assert.Single(user.ProviderData);
266304
Assert.Empty(user.CustomClaims);
305+
}
267306

268-
// Delete user
269-
await this.Auth.DeleteUserAsync(uid);
270-
var exception = await Assert.ThrowsAsync<FirebaseAuthException>(
271-
() => this.Auth.GetUserAsync(uid));
307+
[Fact]
308+
public async Task DeleteUser()
309+
{
310+
var user = await this.userBuilder.CreateUserAsync(new UserRecordArgs());
272311

312+
await this.Auth.DeleteUserAsync(user.Uid);
313+
314+
var exception = await Assert.ThrowsAsync<FirebaseAuthException>(
315+
() => this.Auth.GetUserAsync(user.Uid));
273316
Assert.Equal(AuthErrorCode.UserNotFound, exception.AuthErrorCode);
274317
}
275318

0 commit comments

Comments
 (0)