-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathGetNamesTests.cs
More file actions
123 lines (107 loc) · 3.15 KB
/
Copy pathGetNamesTests.cs
File metadata and controls
123 lines (107 loc) · 3.15 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
namespace NpgsqlRestTests
{
public static partial class Database
{
public static void TsClientGetNamesTests()
{
script.Append("""
create schema if not exists tsclient_test;
create function tsclient_test.get_names()
returns setof text
language sql
as $$
select unnest(array['Alice', 'Bob', 'Charlie']);
$$;
comment on function tsclient_test.get_names() is '
tsclient_module=get_names
';
create function tsclient_test.get_names_status()
returns setof text
language sql
as $$
select unnest(array['Alice', 'Bob', 'Charlie']);
$$;
comment on function tsclient_test.get_names_status() is '
tsclient_module=get_names_status
tsclient_status_code=true
';
""");
}
}
}
namespace NpgsqlRestTests.TsClientTests
{
[Collection("TestFixture")]
public class GetNamesTests
{
private const string Expected = """
const baseUrl = "";
/**
* function tsclient_test.get_names()
* returns setof text
*
* @remarks
* comment on function tsclient_test.get_names is 'tsclient_module=get_names
*
* @returns {string[]}
*
* @see FUNCTION tsclient_test.get_names
*/
export async function tsclientTestGetNames() : Promise<string[]> {
const response = await fetch(baseUrl + "/api/tsclient-test/get-names", {
method: "GET",
headers: {
"Content-Type": "application/json"
},
});
return await response.json() as string[];
}
""";
[Fact]
public void Test_GetNames_GeneratedFile()
{
var filePath = Path.Combine(Setup.Program.TsClientOutputPath, "get_names.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.get_names_status()
* returns setof text
*
* @remarks
* comment on function tsclient_test.get_names_status is 'tsclient_module=get_names_status
* tsclient_status_code=true';
*
* @returns {ApiResult<string[]>}
*
* @see FUNCTION tsclient_test.get_names_status
*/
export async function tsclientTestGetNamesStatus() : Promise<ApiResult<string[]>> {
const response = await fetch(baseUrl + "/api/tsclient-test/get-names-status", {
method: "GET",
headers: {
"Content-Type": "application/json"
},
});
return {
status: response.status,
response: response.ok ? await response.json() as string[] : undefined!,
error: !response.ok && response.headers.get("content-length") !== "0" ? await response.json() as ApiError : undefined
};
}
""";
[Fact]
public void Test_GetNamesStatus_GeneratedFile()
{
var filePath = Path.Combine(Setup.Program.TsClientOutputPath, "get_names_status.ts");
File.Exists(filePath).Should().BeTrue($"Expected file at {filePath}");
var content = File.ReadAllText(filePath);
content.Should().Be(ExpectedStatus);
}
}
}