-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathIsActiveTests.cs
More file actions
117 lines (101 loc) · 2.9 KB
/
Copy pathIsActiveTests.cs
File metadata and controls
117 lines (101 loc) · 2.9 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
namespace NpgsqlRestTests
{
public static partial class Database
{
public static void TsClientIsActiveTests()
{
script.Append("""
create schema if not exists tsclient_test;
create function tsclient_test.is_active()
returns boolean
language sql
as $$
select true;
$$;
comment on function tsclient_test.is_active() is '
tsclient_module=is_active
';
create function tsclient_test.is_active_status()
returns boolean
language sql
as $$
select true;
$$;
comment on function tsclient_test.is_active_status() is '
tsclient_module=is_active_status
tsclient_status_code=true
';
""");
}
}
}
namespace NpgsqlRestTests.TsClientTests
{
[Collection("TestFixture")]
public class IsActiveTests
{
private const string Expected = """
const baseUrl = "";
/**
* function tsclient_test.is_active()
* returns boolean
*
* @remarks
* comment on function tsclient_test.is_active is 'tsclient_module=is_active
*
* @returns {boolean}
*
* @see FUNCTION tsclient_test.is_active
*/
export async function tsclientTestIsActive() : Promise<boolean> {
const response = await fetch(baseUrl + "/api/tsclient-test/is-active", {
method: "POST",
});
return await response.text() == "t";
}
""";
[Fact]
public void Test_IsActive_GeneratedFile()
{
var filePath = Path.Combine(Setup.Program.TsClientOutputPath, "is_active.ts");
File.Exists(filePath).Should().BeTrue($"Expected file at {filePath}");
var content = File.ReadAllText(filePath);
content.Should().Be(Expected);
}
private const string ExpectedStatus = """
const baseUrl = "";
type ApiError = {status: number; title: string; detail?: string | null};
type ApiResult<T> = {status: number, response: T, error: ApiError | undefined};
/**
* function tsclient_test.is_active_status()
* returns boolean
*
* @remarks
* comment on function tsclient_test.is_active_status is 'tsclient_module=is_active_status
* tsclient_status_code=true';
*
* @returns {ApiResult<boolean>}
*
* @see FUNCTION tsclient_test.is_active_status
*/
export async function tsclientTestIsActiveStatus() : Promise<ApiResult<boolean>> {
const response = await fetch(baseUrl + "/api/tsclient-test/is-active-status", {
method: "POST",
});
return {
status: response.status,
response: response.ok ? await response.text() == "t" : undefined!,
error: !response.ok && response.headers.get("content-length") !== "0" ? await response.json() as ApiError : undefined
};
}
""";
[Fact]
public void Test_IsActiveStatus_GeneratedFile()
{
var filePath = Path.Combine(Setup.Program.TsClientOutputPath, "is_active_status.ts");
File.Exists(filePath).Should().BeTrue($"Expected file at {filePath}");
var content = File.ReadAllText(filePath);
content.Should().Be(ExpectedStatus);
}
}
}