forked from PalisadoesFoundation/talawa-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PalisadoesFoundation#1415 feature request deleting advertisements (Pa…
…lisadoesFoundation#1416) * Add: Advert model * Add: Advert model * Add: graphql types * Add: createAd, removeAd, getAllAds * 2 * 2 * Ad: 3 * Added: Typedefs * Test: removeadvertisement * test: get advertisement * fix * fix: errors * updated add types * Added Delete Advertisement Mutations * fix * Add: tests * Add: tests w * fixed: tests
- Loading branch information
1 parent
9e4d2fc
commit e0db32f
Showing
9 changed files
with
129 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { MutationResolvers } from "../../types/generatedGraphQLTypes"; | ||
import { Advertisement } from "../../models"; | ||
|
||
/** | ||
* This function enables to delete a donation record from the database. | ||
* @param _parent - parent of current request | ||
* @param args - payload provided with the request | ||
* @returns Boolean value denoting whether the deletion was successful or not. | ||
*/ | ||
export const deleteAdvertisementById: MutationResolvers["deleteAdvertisementById"] = | ||
async (_parent: any, args: { id: any }) => { | ||
const deletedAdvertisement = await Advertisement.deleteOne({ | ||
_id: args.id, | ||
}); | ||
|
||
return { success: deletedAdvertisement.deletedCount ? true : false }; | ||
}; |
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
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import "dotenv/config"; | ||
import type { Document } from "mongoose"; | ||
import type mongoose from "mongoose"; | ||
import { Types } from "mongoose"; | ||
import type { | ||
InterfaceAdvertisement, | ||
InterfaceDonation, | ||
} from "../../../src/models"; | ||
import { Advertisement } from "../../../src/models"; | ||
import type { MutationDeleteDonationByIdArgs } from "../../../src/types/generatedGraphQLTypes"; | ||
import { connect, disconnect } from "../../helpers/db"; | ||
import { beforeAll, afterAll, describe, it, expect } from "vitest"; | ||
import { createTestUserAndOrganization } from "../../helpers/userAndOrg"; | ||
import { deleteAdvertisementById } from "../../../src/resolvers/Mutation/deleteAdvertisementById"; | ||
|
||
let testAdvertisement: InterfaceAdvertisement & | ||
Document<any, any, InterfaceDonation>; | ||
let MONGOOSE_INSTANCE: typeof mongoose; | ||
|
||
beforeAll(async () => { | ||
MONGOOSE_INSTANCE = await connect(); | ||
const temp = await createTestUserAndOrganization(); | ||
const testOrganization = temp[1]; | ||
testAdvertisement = await Advertisement.create({ | ||
orgId: testOrganization?._id, | ||
endDate: new Date(), | ||
link: "http://example.com", | ||
startDate: new Date(), | ||
type: "POPUP", | ||
name: "Cookies at just $5 for a packet", | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await disconnect(MONGOOSE_INSTANCE); | ||
}); | ||
|
||
describe("resolvers -> Mutation -> deleteAdvertiementById", () => { | ||
it(`returns false if deletion of advertisement was unsuccessful`, async () => { | ||
const args: MutationDeleteDonationByIdArgs = { | ||
id: Types.ObjectId().toString(), | ||
}; | ||
|
||
const deleteDonationByIdPayload = await deleteAdvertisementById?.( | ||
{}, | ||
args, | ||
{} | ||
); | ||
|
||
expect(deleteDonationByIdPayload).toEqual({ | ||
success: false, | ||
}); | ||
}); | ||
|
||
it(`returns true if deletion of ads was successful`, async () => { | ||
const args: MutationDeleteDonationByIdArgs = { | ||
id: testAdvertisement._id, | ||
}; | ||
|
||
const deleteDonationByIdPayload = await deleteAdvertisementById?.( | ||
{}, | ||
args, | ||
{} | ||
); | ||
|
||
expect(deleteDonationByIdPayload).toEqual({ | ||
success: true, | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import "dotenv/config"; | ||
import { connect, disconnect } from "../../helpers/db"; | ||
import type mongoose from "mongoose"; | ||
import { Advertisement } from "../../../src/models"; | ||
import { beforeAll, afterAll, describe, it, expect } from "vitest"; | ||
import { createTestPlugin } from "../../helpers/plugins"; | ||
import { getAdvertisements } from "../../../src/resolvers/Query/getAdvertisements"; | ||
|
||
let MONGOOSE_INSTANCE: typeof mongoose; | ||
|
||
beforeAll(async () => { | ||
MONGOOSE_INSTANCE = await connect(); | ||
await createTestPlugin(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await disconnect(MONGOOSE_INSTANCE); | ||
}); | ||
|
||
describe("resolvers -> Query -> getAdvertisment", () => { | ||
it(`returns list of all existing advertisement`, async () => { | ||
const adsPayload = await getAdvertisements?.({}, {}, {}); | ||
|
||
const ads = await Advertisement.find().lean(); | ||
|
||
expect(adsPayload).toEqual(ads); | ||
}); | ||
}); |