-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathbasic-api.e2e-spec.ts
More file actions
116 lines (95 loc) · 3.23 KB
/
Copy pathbasic-api.e2e-spec.ts
File metadata and controls
116 lines (95 loc) · 3.23 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
import { Test, TestingModule } from "@nestjs/testing";
import { INestApplication } from "@nestjs/common";
import * as request from "supertest";
import { HealthModule } from "../../src/health/health.module";
import { ScannerModule } from "../../src/scanner/scanner.module";
import { RulesModule } from "../../src/rules/rules.module";
describe("Basic API E2E Tests", () => {
let app: INestApplication;
beforeAll(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [HealthModule, ScannerModule, RulesModule],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
});
afterAll(async () => {
if (app) {
await app.close();
}
});
it("should return health check status", async () => {
const response = await request(app.getHttpServer())
.get("/health")
.expect(200);
expect(response.body).toHaveProperty("status");
expect(response.body).toHaveProperty("service");
expect(response.body.status).toBe("healthy");
});
it("should return health readiness", async () => {
const response = await request(app.getHttpServer())
.get("/health/ready")
.expect(200);
expect(response.body).toHaveProperty("status", "healthy");
});
it("should return health liveness", async () => {
const response = await request(app.getHttpServer())
.get("/health/live")
.expect(200);
expect(response.body).toHaveProperty("status", "healthy");
});
it("should scan code successfully", async () => {
const response = await request(app.getHttpServer())
.post("/scanner/scan")
.send({
code: `
use soroban_sdk::{contract, contractimpl, contracttype, Address, Env};
#[contracttype]
pub struct TestContract {
pub owner: Address,
pub counter: u64,
}
#[contractimpl]
impl TestContract {
pub fn new(owner: Address) -> Self {
Self {
owner,
counter: 0,
}
}
pub fn increment(&mut self) {
self.counter += 1;
}
}
`,
source: "test-contract.rs",
})
.expect(200);
expect(response.body).toHaveProperty("scanTime");
expect(response.body).toHaveProperty("violations");
expect(response.body).toHaveProperty("hasViolations");
});
it("should get all rules", async () => {
const response = await request(app.getHttpServer())
.get("/rules")
.expect(200);
expect(Array.isArray(response.body)).toBeTruthy();
expect(response.body.length).toBeGreaterThan(0);
});
it("should handle 404 for non-existent routes", async () => {
const response = await request(app.getHttpServer())
.get("/non-existent-endpoint")
.expect(404);
expect(response.body).toBeDefined();
});
it("should handle empty code gracefully", async () => {
const response = await request(app.getHttpServer())
.post("/scanner/scan")
.send({
code: "",
source: "empty-test",
})
.expect(200);
expect(response.body).toHaveProperty("violations");
});
});