
- Updated `.env` and `.env.test` files to include PostgreSQL connection settings and Redis configuration. - Migrated database from SQLite to PostgreSQL, updating relevant queries and connection logic. - Enhanced error handling and logging throughout the application. - Added new test utilities for PostgreSQL integration and updated user model methods. - Introduced new routes for user authentication and form management, ensuring compatibility with the new database structure. - Created login and registration views in EJS for user interaction.
59 lines
1.9 KiB
JavaScript
59 lines
1.9 KiB
JavaScript
// __tests__/integration/dashboard.test.js
|
|
// ... imports ...
|
|
describe("GET /dashboard (My Forms)", () => {
|
|
let userToken;
|
|
let userId;
|
|
beforeEach(async () => {
|
|
// Create user and login to get token
|
|
const user = await User.create({
|
|
email: "dash@example.com",
|
|
password: "Password123!",
|
|
is_verified: 1,
|
|
});
|
|
userId = user.id;
|
|
const loginRes = await request(app)
|
|
.post("/api/auth/login")
|
|
.send({ email: "dash@example.com", password: "Password123!" });
|
|
userToken = loginRes.body.data.accessToken;
|
|
|
|
// Create some forms for this user
|
|
await pool.query(
|
|
"INSERT INTO forms (uuid, user_id, name) VALUES ($1, $2, $3), ($4, $2, $5)",
|
|
[
|
|
require("uuid").v4(),
|
|
userId,
|
|
"My First Form",
|
|
require("uuid").v4(),
|
|
"My Second Form",
|
|
]
|
|
);
|
|
// Create a form for another user
|
|
const otherUser = await User.create({
|
|
email: "other@example.com",
|
|
password: "Password123!",
|
|
});
|
|
await pool.query(
|
|
"INSERT INTO forms (uuid, user_id, name) VALUES ($1, $2, $3)",
|
|
[require("uuid").v4(), otherUser.id, "Other Users Form"]
|
|
);
|
|
});
|
|
|
|
it("should list forms owned by the authenticated user", async () => {
|
|
const res = await request(app)
|
|
.get("/dashboard")
|
|
.set("Authorization", `Bearer ${userToken}`); // Or handle session if dashboard uses sessions
|
|
|
|
// If dashboard uses sessions, you need to manage login via supertest's agent:
|
|
// const agent = request.agent(app);
|
|
// await agent.post('/api/auth/login').send({ email: 'dash@example.com', password: 'Password123!' });
|
|
// const res = await agent.get('/dashboard');
|
|
|
|
expect(res.statusCode).toEqual(200);
|
|
// For EJS, you'd check for HTML content:
|
|
expect(res.text).toContain("My First Form");
|
|
expect(res.text).toContain("My Second Form");
|
|
expect(res.text).not.toContain("Other Users Form");
|
|
});
|
|
// ... more dashboard tests for create, settings, submissions view, API keys...
|
|
});
|