-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathGreetTests.cs
More file actions
137 lines (119 loc) · 3.3 KB
/
Copy pathGreetTests.cs
File metadata and controls
137 lines (119 loc) · 3.3 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
namespace NpgsqlRestTests
{
public static partial class Database
{
public static void TsClientGreetTests()
{
script.Append("""
create schema if not exists tsclient_test;
create function tsclient_test.greet(_name text)
returns text
language sql
as $$
select 'Hello, ' || _name || '!';
$$;
comment on function tsclient_test.greet(text) is '
tsclient_module=greet
';
create function tsclient_test.greet_status(_name text)
returns text
language sql
as $$
select 'Hello, ' || _name || '!';
$$;
comment on function tsclient_test.greet_status(text) is '
tsclient_module=greet_status
tsclient_status_code=true
';
""");
}
}
}
namespace NpgsqlRestTests.TsClientTests
{
[Collection("TestFixture")]
public class GreetTests
{
private const string Expected = """
const baseUrl = "";
interface ITsclientTestGreetRequest {
name: string | null;
}
/**
* function tsclient_test.greet(
* _name text
* )
* returns text
*
* @remarks
* comment on function tsclient_test.greet is 'tsclient_module=greet
*
* @param request - Object containing request parameters.
* @returns {string}
*
* @see FUNCTION tsclient_test.greet
*/
export async function tsclientTestGreet(
request: ITsclientTestGreetRequest
) : Promise<string> {
const response = await fetch(baseUrl + "/api/tsclient-test/greet", {
method: "POST",
body: JSON.stringify(request)
});
return await response.text();
}
""";
[Fact]
public void Test_Greet_GeneratedFile()
{
var filePath = Path.Combine(Setup.Program.TsClientOutputPath, "greet.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};
interface ITsclientTestGreetStatusRequest {
name: string | null;
}
/**
* function tsclient_test.greet_status(
* _name text
* )
* returns text
*
* @remarks
* comment on function tsclient_test.greet_status is 'tsclient_module=greet_status
* tsclient_status_code=true';
*
* @param request - Object containing request parameters.
* @returns {ApiResult<string>}
*
* @see FUNCTION tsclient_test.greet_status
*/
export async function tsclientTestGreetStatus(
request: ITsclientTestGreetStatusRequest
) : Promise<ApiResult<string>> {
const response = await fetch(baseUrl + "/api/tsclient-test/greet-status", {
method: "POST",
body: JSON.stringify(request)
});
return {
status: response.status,
response: response.ok ? await response.text() : undefined!,
error: !response.ok && response.headers.get("content-length") !== "0" ? await response.json() as ApiError : undefined
};
}
""";
[Fact]
public void Test_GreetStatus_GeneratedFile()
{
var filePath = Path.Combine(Setup.Program.TsClientOutputPath, "greet_status.ts");
File.Exists(filePath).Should().BeTrue($"Expected file at {filePath}");
var content = File.ReadAllText(filePath);
content.Should().Be(ExpectedStatus);
}
}
}