Skip to content

Commit 4150953

Browse files
committed
Fix tests
1 parent 72a6839 commit 4150953

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

packages/rest/e2e-basic-controller/api/posts/post.controller.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class PostController implements AbstractAssemblage {
1515
@Get('/')
1616
public findAll(_req: Request, res: Response) {
1717
const posts = this.repository.findAll();
18-
res.status(200).send(JSON.stringify(posts || []));
18+
res.status(200).json(posts || []);
1919
}
2020

2121
@Get('/sender/:id')
@@ -24,7 +24,7 @@ export class PostController implements AbstractAssemblage {
2424
if (!posts) {
2525
res.sendStatus(404);
2626
}
27-
res.status(200).send(JSON.stringify(posts));
27+
res.status(200).json(posts);
2828
}
2929

3030
@Get('/receiver/:id')
@@ -33,20 +33,20 @@ export class PostController implements AbstractAssemblage {
3333
if (!posts) {
3434
res.sendStatus(404);
3535
}
36-
res.status(200).send(JSON.stringify(posts));
36+
res.status(200).json(posts);
3737
}
3838

3939
@Post('/')
4040
public create(req: Request, res: Response) {
4141
const post = this.repository.create(req.body);
42-
res.status(201).send(JSON.stringify(post));
42+
res.status(201).json(post);
4343
}
4444

4545
@Delete('/delete/:id')
4646
public delete(req: Request, res: Response) {
4747
const deleted = this.repository.delete(Number(req.params.id));
4848
if (deleted) {
49-
res.status(200).send(JSON.stringify(deleted));
49+
res.status(200).json(deleted);
5050
}
5151
res.sendStatus(404);
5252
}

packages/rest/e2e-basic-controller/api/user/user.controller.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class UserController implements AbstractAssemblage {
1515
@Get('/')
1616
public findAll(_req: Request, res: Response) {
1717
const users = this.repository.findAll();
18-
res.status(200).send(JSON.stringify(users || []));
18+
res.status(200).json(Array.isArray(users) ? users : []);
1919
}
2020

2121
@Head('/headers')
@@ -29,50 +29,52 @@ export class UserController implements AbstractAssemblage {
2929

3030
@Get('/id/:id')
3131
public findById(req: Request, res: Response) {
32-
const user = this.repository.findById(req.params.id);
32+
const id = String(req.params.id).trim();
33+
const user = this.repository.findById(id);
3334
if (!user) {
3435
res.sendStatus(404);
36+
return;
3537
}
36-
res.status(200).send(JSON.stringify(user));
38+
res.status(200).json(user);
3739
}
3840

3941
@Get('/gender/:gender')
4042
public findByGender(req: Request, res: Response) {
41-
const user = this.repository.findByGender(req.params.gender);
43+
const gender = String(req.params.gender).trim();
44+
const user = this.repository.findByGender(gender);
4245
if (!user) {
4346
res.sendStatus(404);
47+
return;
4448
}
45-
res.status(200).send(
46-
JSON.stringify({
47-
...user,
48-
})
49-
);
49+
res.status(200).json(user);
5050
}
5151

5252
@Post('/')
5353
public create(req: Request, res: Response) {
5454
const user = this.repository.create(req.body);
55-
res.status(201).send(JSON.stringify(user));
55+
res.status(201).json(user);
5656
}
5757

5858
@Put('/replace/:id')
5959
public replace(req: Request, res: Response) {
60-
const user = this.repository.modify(req.params.id, req.body);
60+
const id = String(req.params.id).trim();
61+
const user = this.repository.modify(id, req.body);
6162
if (!user) {
6263
res.sendStatus(404);
6364
return;
6465
}
65-
res.status(200).send(JSON.stringify(user));
66+
res.status(200).json(user);
6667
}
6768

6869
@Patch('/modify/:id')
6970
public modify(req: Request, res: Response) {
70-
const user = this.repository.modify(req.params.id, req.body);
71+
const id = String(req.params.id).trim();
72+
const user = this.repository.modify(id, req.body);
7173
if (!user) {
7274
res.sendStatus(404);
7375
return;
7476
}
75-
res.status(200).send(JSON.stringify(user));
77+
res.status(200).json(user);
7678
}
7779
/*
7880
@All('/')

0 commit comments

Comments
 (0)