-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from Whats-Cookin/revert-111-dev
Revert "Deploying to production"
- Loading branch information
Showing
12 changed files
with
518 additions
and
819 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,148 +1,89 @@ | ||
import request from "supertest"; | ||
import { app } from "../src"; | ||
import request from 'supertest'; | ||
import { app } from '../src'; | ||
import { prisma } from "../src/db/prisma"; | ||
import jwt from "jsonwebtoken"; | ||
|
||
describe("Integration tests", () => { | ||
describe("POST /claims", () => { | ||
let token: string; | ||
|
||
describe("Intergration tests", ()=>{ | ||
describe('POST /claims', () => { | ||
let token: string; | ||
|
||
beforeAll(() => { | ||
// Generate a JWT token for testing | ||
token = jwt.sign({ aud: 1234 }, process.env.ACCESS_SECRET as string); | ||
}); | ||
|
||
afterAll(async () => { | ||
// Disconnect Prisma client after all tests | ||
await prisma.$disconnect(); | ||
|
||
describe('claimPost', () => { | ||
afterAll(async () => { | ||
// Disconnect Prisma client after all tests | ||
await prisma.$disconnect(); | ||
}); | ||
|
||
it('should create a new claim', async () => { | ||
const newClaim = { | ||
subject: 'Test Claim', | ||
claim: 'This is a test claim', | ||
}; | ||
|
||
const response = await request(app) | ||
.post('/api/claim').set('Authorization', `Bearer ${token}`) | ||
.send(newClaim); | ||
|
||
// Verify that the response status is 201 Created | ||
expect(response.status).toBe(201); | ||
|
||
// Verify that the response body matches the expected claimData | ||
expect(response.body.subject).toBe(newClaim.subject); | ||
expect(response.body.claim).toBe(newClaim.claim); | ||
}, 10000); | ||
}); | ||
|
||
it("should create a new claim with its name and images", async () => { | ||
const newClaim = { | ||
claim: "test", | ||
effectiveDate: "2024-04-23", | ||
subject: "www.test.com", | ||
name: "test name", | ||
images: [ | ||
{ | ||
url: "any test url", | ||
metadata: { | ||
description: "test description", | ||
comment: "test comment" | ||
}, | ||
effectiveDate: "2024-04-23", | ||
owner: "test owner", | ||
signature: "test signature" | ||
} | ||
] | ||
}; | ||
|
||
const response = await request(app) | ||
.post("/api/claim") | ||
.set("Authorization", `Bearer ${token}`) | ||
.send(newClaim); | ||
|
||
// Log the response for debugging | ||
// console.log(response.body); | ||
|
||
// Verify that the response status is 201 Created | ||
expect(response.status).toBe(201); | ||
|
||
// Verify that the response body matches the expected claimData | ||
const responseBody = response.body.claim; | ||
expect(responseBody.subject).toBe(newClaim.subject); | ||
expect(responseBody.claim).toBe(newClaim.claim); | ||
|
||
expect(response.body.claimData).toEqual( | ||
expect.objectContaining({ | ||
name: newClaim.name | ||
}) | ||
); | ||
|
||
// Verify the images separately since they are nested | ||
const responseImages = response.body.claimImages; | ||
expect(responseImages).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
url: newClaim.images[0].url, | ||
metadata: expect.objectContaining(newClaim.images[0].metadata), | ||
effectiveDate: new Date(newClaim.images[0].effectiveDate).toISOString(), | ||
owner: newClaim.images[0].owner, | ||
signature: newClaim.images[0].signature | ||
}) | ||
]) | ||
); | ||
}, 10000); | ||
}); | ||
|
||
// claimGet function | ||
describe("GET /claims", () => { | ||
afterAll(async () => { | ||
await prisma.$disconnect(); | ||
}); | ||
|
||
it("should get all claims if no query params provided", async () => { | ||
// const response = await request(app).get("/api/claim"); // not working | ||
const response = await request(app).get("/api/claims-all"); | ||
|
||
const response = await request(app).get("/api/claim"); | ||
|
||
expect(response.status).toBe(201); | ||
expect(response.body.claimsData.length).toBeGreaterThan(0); | ||
expect(response.body.claimsData[0].claim).toBeDefined(); | ||
expect(response.body.claimsData[0].images).toBeDefined(); | ||
expect(response.body.claimsData[0].data).toBeDefined(); | ||
expect(response.body.claims.length).toBeGreaterThan(0); | ||
expect(response.body.count).toBeGreaterThan(0); | ||
}); | ||
|
||
|
||
// ======== working | ||
|
||
it("should return a specific claim if claimId is provided", async () => { | ||
|
||
it('should return a specific claim if claimId is provided', async () => { | ||
const claim = await prisma.claim.findFirst(); | ||
const data = await prisma.claimData.findFirst({ | ||
where: { | ||
claimId: claim?.id | ||
} | ||
}); | ||
const images = await prisma.image.findMany({ | ||
where: { | ||
claimId: claim?.id | ||
} | ||
|
||
const claimWithDates = Object.assign({}, claim, { | ||
createdAt: "2023-03-12T22:55:40.604Z", | ||
lastUpdatedAt: "2023-03-12T22:55:40.604Z" | ||
}); | ||
|
||
// const claimWithDates = Object.assign({}, claim, { | ||
// createdAt: "2023-03-12T22:55:40.604Z", | ||
// lastUpdatedAt: "2023-03-12T22:55:40.604Z" | ||
// }); // whyyyyyyyyyyy???????? | ||
const response = await request(app).get(`/api/claim/${claim?.id}`); | ||
expect(response.status).toBe(201); | ||
// expect(response.body).toEqual(claimWithDates); | ||
expect(response.body.claim.id).toBe(claim?.id); | ||
expect(response.body.claimData).toEqual(data); | ||
expect(response.body.claimImages).toHaveProperty("length", images.length); | ||
expect(response.body).toEqual(claimWithDates); | ||
}); | ||
|
||
|
||
it("should return filtered claims if search query is provided", async () => { | ||
const searchQuery = "test"; | ||
const response = await request(app).get( | ||
`/api/claim/search?search=${searchQuery}` | ||
); // Corrected route | ||
|
||
|
||
it("should return filtered claims if search query is provided", async () => { | ||
const searchQuery = "claim"; | ||
const response = await request(app).get(`/api/claim?search=${searchQuery}`); | ||
expect(response.status).toBe(201); | ||
expect(response.body.claims.length).toBeGreaterThan(0); | ||
expect(response.body.count).toBeGreaterThan(0); | ||
expect(response.body.claims[0].images).toBeDefined(); | ||
}); | ||
|
||
|
||
it("should return 404 if claim with provided id does not exist", async () => { | ||
const nonExistentClaimId = 999; | ||
|
||
const response = await request(app).get( | ||
`/api/claims/${nonExistentClaimId}` | ||
); | ||
|
||
|
||
const response = await request(app).get(`/api/claims/${nonExistentClaimId}`); | ||
|
||
expect(response.status).toBe(404); | ||
expect(response.body.message).toBe("Not Found"); | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.