-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathDisableApiIntegrationTests.cs
More file actions
120 lines (108 loc) · 3.39 KB
/
DisableApiIntegrationTests.cs
File metadata and controls
120 lines (108 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using AiCommitMessage.Options;
using AiCommitMessage.Services;
using FluentAssertions;
namespace AiCommitMessage.Tests.Integration;
public class DisableApiIntegrationTests
{
/// <summary>
/// Tests the complete workflow when API is disabled.
/// </summary>
[Fact]
public void CompleteWorkflow_Should_WorkCorrectly_When_ApiDisabled()
{
// Arrange
Environment.SetEnvironmentVariable(
"DOTNET_AICOMMITMESSAGE_DISABLE_API",
"true",
EnvironmentVariableTarget.Process
);
var service = new GenerateCommitMessageService();
var options = new GenerateCommitMessageOptions
{
Branch = "feature/246-add-disable-api-option",
Diff = "Added new environment variable support",
Message = "Add option to disable API calls",
};
try
{
// Act
var result = service.GenerateCommitMessage(options);
// Assert
result.Should().Be("#246 Add option to disable API calls");
}
finally
{
// Cleanup
Environment.SetEnvironmentVariable(
"DOTNET_AICOMMITMESSAGE_DISABLE_API",
null,
EnvironmentVariableTarget.Process
);
}
}
/// <summary>
/// Integration test to verify settings service works when API is disabled.
/// </summary>
[Fact]
public void SettingsService_Should_WorkCorrectly_When_ApiDisabled()
{
// Arrange
Environment.SetEnvironmentVariable(
"DOTNET_AICOMMITMESSAGE_DISABLE_API",
"true",
EnvironmentVariableTarget.Process
);
var options = new SetSettingsOptions { Model = "gpt-4o-mini" };
try
{
// Act & Assert - Should not throw exception
var act = () => SettingsService.SetSettings(options);
act.Should().NotThrow();
}
finally
{
// Cleanup
Environment.SetEnvironmentVariable(
"DOTNET_AICOMMITMESSAGE_DISABLE_API",
null,
EnvironmentVariableTarget.Process
);
}
}
/// <summary>
/// Tests the complete workflow when API errors are ignored.
/// </summary>
[Fact]
public void CompleteWorkflow_Should_WorkCorrectly_When_ApiErrorsIgnored()
{
// Arrange
Environment.SetEnvironmentVariable(
"DOTNET_AICOMMITMESSAGE_IGNORE_API_ERRORS",
"true",
EnvironmentVariableTarget.Process
);
var service = new GenerateCommitMessageService();
var options = new GenerateCommitMessageOptions
{
Branch = "feature/285-ignore-api-errors",
Diff = "Added new environment variable support",
Message = "Add option to ignore API errors -skipai", // Use skipai to avoid actual API calls
};
try
{
// Act
var result = service.GenerateCommitMessage(options);
// Assert
result.Should().Be("#285 Add option to ignore API errors");
}
finally
{
// Cleanup
Environment.SetEnvironmentVariable(
"DOTNET_AICOMMITMESSAGE_IGNORE_API_ERRORS",
null,
EnvironmentVariableTarget.Process
);
}
}
}