-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSumArrayTests.cs
More file actions
137 lines (119 loc) · 3.5 KB
/
Copy pathSumArrayTests.cs
File metadata and controls
137 lines (119 loc) · 3.5 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 TsClientSumArrayTests()
{
script.Append("""
create schema if not exists tsclient_test;
create function tsclient_test.sum_array(_numbers int[])
returns int
language sql
as $$
select coalesce(sum(n), 0)::int from unnest(_numbers) as n;
$$;
comment on function tsclient_test.sum_array(int[]) is '
tsclient_module=sum_array
';
create function tsclient_test.sum_array_status(_numbers int[])
returns int
language sql
as $$
select coalesce(sum(n), 0)::int from unnest(_numbers) as n;
$$;
comment on function tsclient_test.sum_array_status(int[]) is '
tsclient_module=sum_array_status
tsclient_status_code=true
';
""");
}
}
}
namespace NpgsqlRestTests.TsClientTests
{
[Collection("TestFixture")]
public class SumArrayTests
{
private const string Expected = """
const baseUrl = "";
interface ITsclientTestSumArrayRequest {
numbers: number[] | null;
}
/**
* function tsclient_test.sum_array(
* _numbers integer[]
* )
* returns integer
*
* @remarks
* comment on function tsclient_test.sum_array is 'tsclient_module=sum_array
*
* @param request - Object containing request parameters.
* @returns {number}
*
* @see FUNCTION tsclient_test.sum_array
*/
export async function tsclientTestSumArray(
request: ITsclientTestSumArrayRequest
) : Promise<number> {
const response = await fetch(baseUrl + "/api/tsclient-test/sum-array", {
method: "POST",
body: JSON.stringify(request)
});
return Number(await response.text());
}
""";
[Fact]
public void Test_SumArray_GeneratedFile()
{
var filePath = Path.Combine(Setup.Program.TsClientOutputPath, "sum_array.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 ITsclientTestSumArrayStatusRequest {
numbers: number[] | null;
}
/**
* function tsclient_test.sum_array_status(
* _numbers integer[]
* )
* returns integer
*
* @remarks
* comment on function tsclient_test.sum_array_status is 'tsclient_module=sum_array_status
* tsclient_status_code=true';
*
* @param request - Object containing request parameters.
* @returns {ApiResult<number>}
*
* @see FUNCTION tsclient_test.sum_array_status
*/
export async function tsclientTestSumArrayStatus(
request: ITsclientTestSumArrayStatusRequest
) : Promise<ApiResult<number>> {
const response = await fetch(baseUrl + "/api/tsclient-test/sum-array-status", {
method: "POST",
body: JSON.stringify(request)
});
return {
status: response.status,
response: response.ok ? Number(await response.text()) : undefined!,
error: !response.ok && response.headers.get("content-length") !== "0" ? await response.json() as ApiError : undefined
};
}
""";
[Fact]
public void Test_SumArrayStatus_GeneratedFile()
{
var filePath = Path.Combine(Setup.Program.TsClientOutputPath, "sum_array_status.ts");
File.Exists(filePath).Should().BeTrue($"Expected file at {filePath}");
var content = File.ReadAllText(filePath);
content.Should().Be(ExpectedStatus);
}
}
}