Skip to content

Commit 45a6674

Browse files
committed
Refactoring PasswordlessTests
1 parent 8596ffd commit 45a6674

File tree

1 file changed

+23
-43
lines changed

1 file changed

+23
-43
lines changed

tests/Auth0.AuthenticationApi.IntegrationTests/PasswordlessTests.cs

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,17 @@ namespace Auth0.AuthenticationApi.IntegrationTests
2121
public class PasswordlessTests : TestBase
2222
{
2323
private AuthenticationApiClient authenticationApiClient;
24-
private string email;
25-
private string phone;
24+
private readonly string email = "dummy-email@dummy.domain";
25+
private readonly string phone = "+911234567890";
2626

2727
public PasswordlessTests()
2828
{
2929
authenticationApiClient = new AuthenticationApiClient(GetVariable("AUTH0_AUTHENTICATION_API_URL"));
30-
email = GetVariable("AUTH0_PASSWORDLESSDEMO_EMAIL", false);
31-
phone = GetVariable("AUTH0_PASSWORDLESSDEMO_PHONE", false);
3230
}
3331

34-
[SkippableFact]
32+
[Fact]
3533
public async Task Can_launch_email_link_flow()
3634
{
37-
Skip.If(string.IsNullOrEmpty(email), "AUTH0_PASSWORDLESSDEMO_EMAIL not set");
38-
3935
var request = new PasswordlessEmailRequest
4036
{
4137
ClientId = GetVariable("AUTH0_CLIENT_ID"),
@@ -51,11 +47,9 @@ public async Task Can_launch_email_link_flow()
5147
response.EmailVerified.Should().NotBeNull();
5248
}
5349

54-
[SkippableFact]
50+
[Fact]
5551
public async Task Can_launch_email_link_flow_with_auth_parameters()
5652
{
57-
Skip.If(string.IsNullOrEmpty(email), "AUTH0_PASSWORDLESSDEMO_EMAIL not set");
58-
5953
var request = new PasswordlessEmailRequest
6054
{
6155
ClientId = GetVariable("AUTH0_CLIENT_ID"),
@@ -78,15 +72,13 @@ public async Task Can_launch_email_link_flow_with_auth_parameters()
7872
response.EmailVerified.Should().NotBeNull();
7973
}
8074

81-
[SkippableFact]
75+
[Fact]
8276
public async Task Can_launch_email_code_flow()
8377
{
84-
Skip.If(string.IsNullOrEmpty(email), "AUTH0_PASSWORDLESSDEMO_EMAIL not set");
85-
8678
var request = new PasswordlessEmailRequest
8779
{
88-
ClientId = GetVariable("AUTH0_CLIENT_ID"),
89-
ClientSecret = GetVariable("AUTH0_CLIENT_SECRET"),
80+
ClientId = GetVariable("AUTH0_SPA_CLIENT_ID"),
81+
ClientSecret = GetVariable("AUTH0_SPA_CLIENT_SECRET"),
9082
Email = email,
9183
Type = PasswordlessEmailRequestType.Code
9284
};
@@ -97,14 +89,12 @@ public async Task Can_launch_email_code_flow()
9789
response.EmailVerified.Should().NotBeNull();
9890
}
9991

100-
[SkippableFact]
92+
[Fact]
10193
public async Task Can_launch_email_code_flow_for_SPA()
10294
{
103-
Skip.If(string.IsNullOrEmpty(email), "AUTH0_PASSWORDLESSDEMO_EMAIL not set");
104-
10595
var request = new PasswordlessEmailRequest
10696
{
107-
ClientId = "Qpnq5llXeWEn1o1iLYNQSr3zFI1YPg3K",
97+
ClientId = GetVariable("AUTH0_SPA_CLIENT_ID"),
10898
Email = email,
10999
Type = PasswordlessEmailRequestType.Code,
110100
AuthenticationParameters = new Dictionary<string, object>
@@ -120,32 +110,24 @@ public async Task Can_launch_email_code_flow_for_SPA()
120110
response.EmailVerified.Should().NotBeNull();
121111
}
122112

123-
[SkippableFact]
113+
[SkippableFact(Skip = "Requires PhoneProvider setup")]
124114
public async Task Can_launch_sms_flow()
125115
{
126-
Skip.If(string.IsNullOrEmpty(phone), "AUTH0_PASSWORDLESSDEMO_PHONE not set");
127-
128-
// Arrange
129-
using (var authenticationApiClient = new AuthenticationApiClient(GetVariable("AUTH0_PASSWORDLESSDEMO_AUTHENTICATION_API_URL")))
116+
// Act
117+
var request = new PasswordlessSmsRequest
130118
{
131-
// Act
132-
var request = new PasswordlessSmsRequest
133-
{
134-
ClientId = GetVariable("AUTH0_PASSWORDLESSDEMO_CLIENT_ID"),
135-
ClientSecret = GetVariable("AUTH0_PASSWORDLESSDEMO_CLIENT_SECRET"),
136-
PhoneNumber = phone
137-
};
138-
var response = await authenticationApiClient.StartPasswordlessSmsFlowAsync(request);
139-
response.Should().NotBeNull();
140-
response.PhoneNumber.Should().Be(request.PhoneNumber);
141-
}
119+
ClientId = GetVariable("AUTH0_SPA_CLIENT_ID"),
120+
ClientSecret = GetVariable("AUTH0_SPA_CLIENT_SECRET"),
121+
PhoneNumber = phone
122+
};
123+
var response = await authenticationApiClient.StartPasswordlessSmsFlowAsync(request);
124+
response.Should().NotBeNull();
125+
response.PhoneNumber.Should().Be(request.PhoneNumber);
142126
}
143127

144-
[Fact(Skip = "Run manually")]
128+
[Fact(Skip = "Involves sending message - receiving code - Using that in test case")]
145129
public async Task Can_exchange_sms_code_for_access_token()
146130
{
147-
var authenticationApiClient = new AuthenticationApiClient(GetVariable("AUTH0_AUTHENTICATION_API_URL"));
148-
149131
// Exchange the code
150132
var token = await authenticationApiClient.GetTokenAsync(new PasswordlessSmsTokenRequest
151133
{
@@ -162,16 +144,14 @@ public async Task Can_exchange_sms_code_for_access_token()
162144
token.Should().NotBeNull();
163145
}
164146

165-
[Fact(Skip = "Run manually")]
147+
[Fact(Skip = "Involves sending an email - receiving a code - using that code to run test")]
166148
public async Task Can_exchange_email_code_for_access_token()
167149
{
168-
var authenticationApiClient = new AuthenticationApiClient(GetVariable("AUTH0_AUTHENTICATION_API_URL"));
169-
170150
// Exchange the code
171151
var token = await authenticationApiClient.GetTokenAsync(new PasswordlessEmailTokenRequest
172152
{
173-
ClientId = GetVariable("AUTH0_PASSWORDLESSDEMO_CLIENT_ID"),
174-
ClientSecret = GetVariable("AUTH0_PASSWORDLESSDEMO_CLIENT_SECRET"),
153+
ClientId = GetVariable("AUTH0_SPA_CLIENT_ID"),
154+
ClientSecret = GetVariable("AUTH0_SPA_CLIENT_SECRET"),
175155
Code = "...",
176156
Audience = GetVariable("AUTH0_MANAGEMENT_API_AUDIENCE"),
177157
Scope = "openid email",

0 commit comments

Comments
 (0)