Skip to content

Commit cf097c7

Browse files
fix(app): init templates now place assert directives at the top of the generated .http files so it matches plugin expectations (#97)
1 parent 746feff commit cf097c7

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

packages/app/src/cmd/init/basic.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,12 @@ describe('collection/users/list.http', () => {
175175
}
176176

177177
export function generateCreatePostRequest(): string {
178-
return `POST {{baseUrl}}/posts
178+
return `# @assert status == 201
179+
180+
POST {{baseUrl}}/posts
179181
Content-Type: application/json
180182
X-Request-ID: {{$uuid()}}
181183
182-
# @assert status == 201
183-
184184
{
185185
"title": "Hello from t-req",
186186
"body": "Created at {{$isodate()}}",
@@ -190,16 +190,16 @@ X-Request-ID: {{$uuid()}}
190190
}
191191

192192
export function generateListUsersRequest(): string {
193-
return `GET {{baseUrl}}/users
194-
Accept: application/json
193+
return `# @assert status == 200
195194
196-
# @assert status == 200
195+
GET {{baseUrl}}/users
196+
Accept: application/json
197197
`;
198198
}
199199

200200
export function generateGetUserRequest(): string {
201-
return `GET {{baseUrl}}/users/{{userId}}
201+
return `# @assert status == 200
202202
203-
# @assert status == 200
203+
GET {{baseUrl}}/users/{{userId}}
204204
`;
205205
}

packages/app/src/cmd/init/empty.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ export function generateEmptyConfig(): string {
6666
}
6767

6868
export function generateHelloRequest(): string {
69-
return `GET {{baseUrl}}/users/1
69+
return `# @assert status == 200
7070
71-
# @assert status == 200
71+
GET {{baseUrl}}/users/1
7272
`;
7373
}
7474

packages/app/test/cmd/init.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,23 @@ describe('generated file contents', () => {
180180
expect(createPost).toContain('{{baseUrl}}/posts');
181181
expect(createPost).toContain('"title"');
182182
expect(createPost).toContain('# @assert status == 201');
183+
expect(createPost.indexOf('# @assert status == 201')).toBeLessThan(
184+
createPost.indexOf('POST {{baseUrl}}/posts')
185+
);
183186
expect(createPost).not.toContain('{{email}}');
184187
expect(createPost).not.toContain('{{password}}');
185188

186189
const listUsers = generateListUsersRequest();
187190
expect(listUsers).toContain('# @assert status == 200');
191+
expect(listUsers.indexOf('# @assert status == 200')).toBeLessThan(
192+
listUsers.indexOf('GET {{baseUrl}}/users')
193+
);
188194

189195
const getUser = generateGetUserRequest();
190196
expect(getUser).toContain('# @assert status == 200');
197+
expect(getUser.indexOf('# @assert status == 200')).toBeLessThan(
198+
getUser.indexOf('GET {{baseUrl}}/users/{{userId}}')
199+
);
191200
});
192201

193202
test('should generate run script that imports from client', () => {
@@ -514,6 +523,9 @@ describe('empty template', () => {
514523
const request = generateHelloRequest();
515524
expect(request).toContain('GET {{baseUrl}}/users/1');
516525
expect(request).toContain('# @assert status == 200');
526+
expect(request.indexOf('# @assert status == 200')).toBeLessThan(
527+
request.indexOf('GET {{baseUrl}}/users/1')
528+
);
517529
});
518530

519531
test('all empty template variables should be defined in config', () => {

0 commit comments

Comments
 (0)