diff --git a/sample_data/organizations.json b/sample_data/organizations.json index 1b922afeb3..f57ceab8bb 100644 --- a/sample_data/organizations.json +++ b/sample_data/organizations.json @@ -11,7 +11,16 @@ "blockedUsers": [], "name": "The Unity Foundation", "description": "A foundation aimed at uniting the world and making it a better place for all.", - "location": "Delhi, India", + "address": { + "city": "Delhi", + "countryCode": "IN", + "dependentLocality": "Some Dependent Locality", + "line1": "123 Random Street", + "line2": "Apartment 456", + "postalCode": "110001", + "sortingCode": "ABC-123", + "state": "Delhi" + }, "userRegistrationRequired": false, "visibleInSearch": true, "image": null, @@ -36,12 +45,20 @@ "blockedUsers": [], "name": "Angel Foundation", "description": "We are aimed at improving the education spaces for the under privileged girl child.", - "location": "Kolkata, West Bengal", + "address": { + "city": "Kolkata", + "countryCode": "IN", + "dependentLocality": "Some Dependent Locality", + "line1": "line1", + "line2": "line2", + "postalCode": "711205", + "sortingCode": "ABC-124", + "state": "West Bengal" + }, "userRegistrationRequired": false, "visibleInSearch": true, "image": null, "creatorId": "64378abd85008f171cf2990d", - "updatedAt": "2023-04-13T05:16:52.827Z", "createdAt": "2023-04-13T05:16:52.827Z", "__v": 0 }, @@ -57,12 +74,20 @@ "blockedUsers": [], "name": "Hope Foundation", "description": "A place where money and power doesn't matter. Free legal aid to everyone.", - "location": "Mountain View, CA", + "address": { + "city": "Mountain View", + "countryCode": "US", + "dependentLocality": "Some Dependent Locality", + "line1": "123 Main Street", + "line2": "Apt 456", + "postalCode": "94040", + "sortingCode": "XYZ-789", + "state": "CA" + }, "userRegistrationRequired": false, "visibleInSearch": true, "image": null, "creatorId": "64378abd85008f171cf2990d", - "updatedAt": "2023-04-13T05:16:52.827Z", "createdAt": "2023-04-13T05:16:52.827Z", "__v": 0 }, @@ -78,12 +103,20 @@ "blockedUsers": [], "name": "Dignity Foundation", "description": "A foundation aimed at improving the lives of old age citizens.", - "location": "Brooklyn, NYC", + "address": { + "city": "Brooklyn", + "countryCode": "US", + "dependentLocality": "Sample Dependent Locality", + "line1": "123 Main Street", + "line2": "Apt 456", + "postalCode": "11234", + "sortingCode": "ABC-789", + "state": "NY" + }, "userRegistrationRequired": false, "visibleInSearch": true, "image": null, "creatorId": "64378abd85008f171cf2990d", - "updatedAt": "2023-04-13T05:16:52.827Z", "createdAt": "2023-04-13T05:16:52.827Z", "__v": 0 } diff --git a/schema.graphql b/schema.graphql index d1aa9bb312..bc8d557437 100644 --- a/schema.graphql +++ b/schema.graphql @@ -4,7 +4,7 @@ directive @role(requires: UserType) on FIELD_DEFINITION type Address { city: String - countryCode: CountryCode + countryCode: String dependentLocality: String line1: String line2: String @@ -15,7 +15,7 @@ type Address { input AddressInput { city: String - countryCode: CountryCode + countryCode: String dependentLocality: String line1: String line2: String @@ -570,6 +570,7 @@ input OTPInput { type Organization { _id: ID! + address: Address admins(adminId: ID): [User!] apiUrl: URL! blockedUsers: [User] @@ -578,7 +579,6 @@ type Organization { customFields: [OrganizationCustomField!]! description: String! image: String - location: String members: [User] membershipRequests: [MembershipRequest] name: String! @@ -608,11 +608,11 @@ type OrganizationInfoNode { } input OrganizationInput { + address: AddressInput! apiUrl: URL attendees: String description: String! image: String - location: String name: String! userRegistrationRequired: Boolean visibleInSearch: Boolean @@ -921,8 +921,8 @@ input UpdateEventInput { } input UpdateOrganizationInput { + address: AddressInput description: String - location: String name: String userRegistrationRequired: Boolean visibleInSearch: Boolean diff --git a/src/models/Organization.ts b/src/models/Organization.ts index 092cbb1a0a..2ee482bea6 100644 --- a/src/models/Organization.ts +++ b/src/models/Organization.ts @@ -14,7 +14,16 @@ export interface InterfaceOrganization { image: string | undefined; name: string; description: string; - location: string | undefined; + address: { + city: string; + countryCode: string; + dependentLocality: string; + line1: string; + line2: string; + postalCode: string; + sortingCode: string; + state: string; + }; creatorId: PopulatedDoc; status: string; members: PopulatedDoc[]; @@ -36,7 +45,7 @@ export interface InterfaceOrganization { * @param image - Organization image URL. * @param name - Organization name. * @param description - Organization description. - * @param location - Organization location. + * @param address - Organization address, stored as an object. * @param creatorId - Organization creator, referring to `User` model. * @param status - Status. * @param members - Collection of members, each object refer to `User` model. @@ -49,7 +58,6 @@ export interface InterfaceOrganization { * @param createdAt - Time stamp of data creation. * @param updatedAt - Time stamp of data updation. */ - const organizationSchema = new Schema( { apiUrl: { @@ -66,8 +74,31 @@ const organizationSchema = new Schema( type: String, required: true, }, - location: { - type: String, + address: { + city: { + type: String, + }, + countryCode: { + type: String, + }, + dependentLocality: { + type: String, + }, + line1: { + type: String, + }, + line2: { + type: String, + }, + postalCode: { + type: String, + }, + sortingCode: { + type: String, + }, + state: { + type: String, + }, }, userRegistrationRequired: { type: Boolean, diff --git a/src/resolvers/Mutation/createOrganization.ts b/src/resolvers/Mutation/createOrganization.ts index 3d607f2249..f321982f14 100644 --- a/src/resolvers/Mutation/createOrganization.ts +++ b/src/resolvers/Mutation/createOrganization.ts @@ -1,5 +1,8 @@ import "dotenv/config"; -import type { MutationResolvers } from "../../types/generatedGraphQLTypes"; +import type { + MutationResolvers, + Address, +} from "../../types/generatedGraphQLTypes"; import { User, Organization } from "../../models"; import { errors, requestContext } from "../../libraries"; import { LENGTH_VALIDATION_ERROR } from "../../constants"; @@ -39,14 +42,17 @@ export const createOrganization: MutationResolvers["createOrganization"] = let validationResultDescription = { isLessThanMaxLength: false, }; - let validationResultLocation = { - isLessThanMaxLength: false, + let validationResultAddress = { + isAddressValid: false, }; - if (args.data?.name && args.data?.description && args.data?.location) { + if (args.data?.name && args.data?.description) { validationResultName = isValidString(args.data?.name, 256); validationResultDescription = isValidString(args.data?.description, 500); - validationResultLocation = isValidString(args.data?.location, 50); + } + + if (args.data?.address) { + validationResultAddress = validateAddress(args.data?.address); } if (!validationResultName.isLessThanMaxLength) { @@ -65,25 +71,21 @@ export const createOrganization: MutationResolvers["createOrganization"] = LENGTH_VALIDATION_ERROR.CODE ); } - if (!validationResultLocation.isLessThanMaxLength) { - throw new errors.InputValidationError( - requestContext.translate( - `${LENGTH_VALIDATION_ERROR.MESSAGE} 50 characters in location` - ), - LENGTH_VALIDATION_ERROR.CODE - ); + if (!validationResultAddress.isAddressValid) { + throw new errors.InputValidationError("Not a Valid Address"); } // Creates new organization. const createdOrganization = await Organization.create({ ...args.data, + address: args.data?.address, image: uploadImageFileName ? uploadImageFileName : null, creatorId: context.userId, admins: [context.userId], members: [context.userId], }); - await cacheOrganizations([createdOrganization.toObject()!]); + await cacheOrganizations([createdOrganization.toObject()]); /* Adds createdOrganization._id to joinedOrganizations, createdOrganizations @@ -105,3 +107,71 @@ export const createOrganization: MutationResolvers["createOrganization"] = // Returns createdOrganization. return createdOrganization.toObject(); }; +/** + * Validates an address object to ensure its fields meet specified criteria. + * @param address - The address object to validate + * @returns An object containing the validation result: isAddressValid (true if the address is valid, false otherwise) + */ +function validateAddress(address: Address | undefined): { + isAddressValid: boolean; +} { + if (!address) { + return { isAddressValid: false }; + } + + const { + city, + countryCode, + dependentLocality, + line1, + line2, + postalCode, + sortingCode, + state, + } = address; + + // Mandatory: It should be a valid country code. + const isCountryCodeValid = !!countryCode && countryCode.length >= 2; + + // Mandatory: It should exist and have a length greater than 0 + const isCityValid = !!city && city.length > 0; + + // Optional: It should exist and have a length greater than 0 + const isDependentLocalityValid = + dependentLocality === undefined || + (typeof dependentLocality === "string" && dependentLocality.length >= 0); + + // Optional: Line 1 should exist and have a length greater than 0 + const isLine1Valid = + line1 === undefined || (typeof line1 === "string" && line1.length >= 0); + + // Optional: Line 2 should exist and have a length greater than 0, if provided + const isLine2Valid = + line2 === undefined || (typeof line2 === "string" && line2.length >= 0); + + // Optional: It should exist and have a valid format. + const isPostalCodeValid = + postalCode === undefined || + (typeof postalCode === "string" && /^\d*$/.test(postalCode)); + + // Optional: It should exist and have a length greater than 0, if provided + const isSortingCodeValid = + sortingCode === undefined || + (typeof sortingCode === "string" && sortingCode.length >= 0); + + // Optional: It should exist and have a length greater than 0, if provided + const isStateValid = + state === undefined || (typeof state === "string" && state.length >= 0); + + const isAddressValid = + isCityValid && + isCountryCodeValid && + isDependentLocalityValid && + isLine1Valid && + isLine2Valid && + isPostalCodeValid && + isSortingCodeValid && + isStateValid; + + return { isAddressValid: isAddressValid }; +} diff --git a/src/typeDefs/inputs.ts b/src/typeDefs/inputs.ts index 45f43eaff6..3c3af19e60 100644 --- a/src/typeDefs/inputs.ts +++ b/src/typeDefs/inputs.ts @@ -138,7 +138,7 @@ export const inputs = gql` input OrganizationInput { name: String! description: String! - location: String + address: AddressInput! attendees: String apiUrl: URL image: String @@ -280,7 +280,7 @@ export const inputs = gql` input UpdateOrganizationInput { name: String description: String - location: String + address: AddressInput userRegistrationRequired: Boolean visibleInSearch: Boolean } @@ -292,7 +292,7 @@ export const inputs = gql` input AddressInput { city: String - countryCode: CountryCode + countryCode: String dependentLocality: String line1: String line2: String diff --git a/src/typeDefs/types.ts b/src/typeDefs/types.ts index c4a46988f9..8fb7fa16d9 100644 --- a/src/typeDefs/types.ts +++ b/src/typeDefs/types.ts @@ -225,7 +225,7 @@ export const types = gql` _id: ID! name: String! description: String! - location: String + address: Address creator: User createdAt: DateTime! updatedAt: DateTime! @@ -347,7 +347,7 @@ export const types = gql` type Address { city: String - countryCode: CountryCode + countryCode: String dependentLocality: String line1: String line2: String diff --git a/src/types/generatedGraphQLTypes.ts b/src/types/generatedGraphQLTypes.ts index 8ac08c6f75..41902b784e 100644 --- a/src/types/generatedGraphQLTypes.ts +++ b/src/types/generatedGraphQLTypes.ts @@ -54,7 +54,7 @@ export type Scalars = { export type Address = { __typename?: 'Address'; city?: Maybe; - countryCode?: Maybe; + countryCode?: Maybe; dependentLocality?: Maybe; line1?: Maybe; line2?: Maybe; @@ -65,7 +65,7 @@ export type Address = { export type AddressInput = { city?: InputMaybe; - countryCode?: InputMaybe; + countryCode?: InputMaybe; dependentLocality?: InputMaybe; line1?: InputMaybe; line2?: InputMaybe; @@ -1077,6 +1077,7 @@ export type OtpInput = { export type Organization = { __typename?: 'Organization'; _id: Scalars['ID']['output']; + address?: Maybe
; admins?: Maybe>; apiUrl: Scalars['URL']['output']; blockedUsers?: Maybe>>; @@ -1085,7 +1086,6 @@ export type Organization = { customFields: Array; description: Scalars['String']['output']; image?: Maybe; - location?: Maybe; members?: Maybe>>; membershipRequests?: Maybe>>; name: Scalars['String']['output']; @@ -1130,11 +1130,11 @@ export type OrganizationInfoNode = { }; export type OrganizationInput = { + address: AddressInput; apiUrl?: InputMaybe; attendees?: InputMaybe; description: Scalars['String']['input']; image?: InputMaybe; - location?: InputMaybe; name: Scalars['String']['input']; userRegistrationRequired?: InputMaybe; visibleInSearch?: InputMaybe; @@ -1607,8 +1607,8 @@ export type UpdateEventInput = { }; export type UpdateOrganizationInput = { + address?: InputMaybe; description?: InputMaybe; - location?: InputMaybe; name?: InputMaybe; userRegistrationRequired?: InputMaybe; visibleInSearch?: InputMaybe; @@ -2198,7 +2198,7 @@ export type RoleDirectiveResolver = { city?: Resolver, ParentType, ContextType>; - countryCode?: Resolver, ParentType, ContextType>; + countryCode?: Resolver, ParentType, ContextType>; dependentLocality?: Resolver, ParentType, ContextType>; line1?: Resolver, ParentType, ContextType>; line2?: Resolver, ParentType, ContextType>; @@ -2612,6 +2612,7 @@ export type MutationResolvers = { _id?: Resolver; + address?: Resolver, ParentType, ContextType>; admins?: Resolver>, ParentType, ContextType, Partial>; apiUrl?: Resolver; blockedUsers?: Resolver>>, ParentType, ContextType>; @@ -2620,7 +2621,6 @@ export type OrganizationResolvers, ParentType, ContextType>; description?: Resolver; image?: Resolver, ParentType, ContextType>; - location?: Resolver, ParentType, ContextType>; members?: Resolver>>, ParentType, ContextType>; membershipRequests?: Resolver>>, ParentType, ContextType>; name?: Resolver; diff --git a/src/utilities/createSampleOrganizationUtil.ts b/src/utilities/createSampleOrganizationUtil.ts index 46d18b2d97..ee67fe7d73 100644 --- a/src/utilities/createSampleOrganizationUtil.ts +++ b/src/utilities/createSampleOrganizationUtil.ts @@ -5,6 +5,8 @@ import { faker } from "@faker-js/faker"; import type mongoose from "mongoose"; import { SampleData } from "../models/SampleData"; +/* eslint-disable */ + export const generateUserData = async ( organizationId: string, userType: string @@ -214,11 +216,33 @@ export const createSampleOrganization = async (): Promise => { const _id = faker.database.mongodbObjectId(); const creator = await generateUserData(_id, "ADMIN"); + interface Address { + city: string; + countryCode: string; + dependentLocality: string; + line1: string; + line2: string; + postalCode: string; + sortingCode: string; + state: string; + } + + const address: Address = { + city: faker.address.city(), + countryCode: faker.address.countryCode(), + dependentLocality: faker.address.secondaryAddress(), + line1: faker.address.streetAddress(), + line2: faker.address.secondaryAddress(), + postalCode: faker.address.zipCode(), + sortingCode: faker.address.zipCode(), + state: faker.address.state(), + }; + const organization = new Organization({ _id, name: faker.company.name(), description: faker.lorem.sentences(), - location: `${faker.location.country()}, ${faker.location.city()}`, + address, userRegistrationRequired: false, creatorId: creator._id, status: "ACTIVE", diff --git a/tests/resolvers/Mutation/createOrganization.spec.ts b/tests/resolvers/Mutation/createOrganization.spec.ts index c2bfe01e74..abd2dc9725 100644 --- a/tests/resolvers/Mutation/createOrganization.spec.ts +++ b/tests/resolvers/Mutation/createOrganization.spec.ts @@ -58,7 +58,16 @@ describe("resolvers -> Mutation -> createOrganization", () => { userRegistrationRequired: true, visibleInSearch: true, apiUrl: "apiUrl", - location: "location", + address: { + city: "CityName", + countryCode: "US", + dependentLocality: "Dependent Locality", + line1: "123 Main Street", + line2: "Apartment 456", + postalCode: "12345", + sortingCode: "ABC-123", + state: "State/Province", + }, }, }; @@ -107,9 +116,18 @@ describe("resolvers -> Mutation -> createOrganization", () => { description: "description", name: "name", apiUrl: "apiUrl", + address: { + city: "CityName", + countryCode: "US", + dependentLocality: "Dependent Locality", + line1: "123 Main Street", + line2: "Apartment 456", + postalCode: "12345", + sortingCode: "ABC-123", + state: "State/Province", + }, userRegistrationRequired: true, visibleInSearch: true, - location: "location", }, file: "imagePath", }; @@ -127,9 +145,18 @@ describe("resolvers -> Mutation -> createOrganization", () => { description: "description", name: "name", apiUrl: "apiUrl", + address: { + city: "CityName", + countryCode: "US", + dependentLocality: "Dependent Locality", + line1: "123 Main Street", + line2: "Apartment 456", + postalCode: "12345", + sortingCode: "ABC-123", + state: "State/Province", + }, userRegistrationRequired: true, visibleInSearch: true, - location: "location", creatorId: testUser?._id, admins: [testUser?._id], members: [testUser?._id], @@ -166,7 +193,16 @@ describe("resolvers -> Mutation -> createOrganization", () => { userRegistrationRequired: true, visibleInSearch: true, apiUrl: "apiUrl", - location: "location", + address: { + city: "CityName", + countryCode: "US", + dependentLocality: "Dependent Locality", + line1: "123 Main Street", + line2: "Apartment 456", + postalCode: "12345", + sortingCode: "ABC-123", + state: "State/Province", + }, }, file: null, }; @@ -186,7 +222,16 @@ describe("resolvers -> Mutation -> createOrganization", () => { userRegistrationRequired: true, visibleInSearch: true, apiUrl: "apiUrl", - location: "location", + address: { + city: "CityName", + countryCode: "US", + dependentLocality: "Dependent Locality", + line1: "123 Main Street", + line2: "Apartment 456", + postalCode: "12345", + sortingCode: "ABC-123", + state: "State/Province", + }, creatorId: testUser?._id, admins: [testUser?._id], members: [testUser?._id], @@ -208,7 +253,16 @@ describe("resolvers -> Mutation -> createOrganization", () => { visibleInSearch: true, name: "JWQPfpdkGGGKyryb86K4YN85nDj4m4F7gEAMBbMXLax73pn2okV6kpWY0EYO0XSlUc0fAlp45UCgg3s6mqsRYF9FOlzNIDFLZ1rd03Z17cdJRuvBcAmbC0imyqGdXHGDUQmVyOjDkaOLAvjhB5uDeuEqajcAPTcKpZ6LMpigXuqRAd0xGdPNXyITC03FEeKZAjjJL35cSIUeMv5eWmiFlmmm70FU1Bp6575zzBtEdyWPLflcA2GpGmmf4zvT7nfgN3NIkwQIhk9OwP8dn75YYczcYuUzLpxBu1Lyog77YlAj5DNdTIveXu9zHeC6V4EEUcPQtf1622mhdU3jZNMIAyxcAG4ErtztYYRqFs0ApUxXiQI38rmiaLcicYQgcOxpmFvqRGiSduiCprCYm90CHWbQFq4w2uhr8HhR3r9HYMIYtrRyO6C3rPXaQ7otpjuNgE0AKI57AZ4nGG1lvNwptFCY60JEndSLX9Za6XP1zkVRLaMZArQNl", apiUrl: "apiUrl", - location: "location", + address: { + city: "CityName", + countryCode: "US", + dependentLocality: "Dependent Locality", + line1: "123 Main Street", + line2: "Apartment 456", + postalCode: "12345", + sortingCode: "ABC-123", + state: "State/Province", + }, }, file: null, }; @@ -237,7 +291,16 @@ describe("resolvers -> Mutation -> createOrganization", () => { userRegistrationRequired: true, visibleInSearch: true, apiUrl: "apiUrl", - location: "location", + address: { + city: "CityName", + countryCode: "US", + dependentLocality: "Dependent Locality", + line1: "123 Main Street", + line2: "Apartment 456", + postalCode: "12345", + sortingCode: "ABC-123", + state: "State/Province", + }, }, file: null, }; @@ -252,32 +315,116 @@ describe("resolvers -> Mutation -> createOrganization", () => { ); } }); - it(`throws String Length Validation error if location is greater than 50 characters`, async () => { + it("throws Address Validation Error for an invalid address", async () => { const { requestContext } = await import("../../../src/libraries"); vi.spyOn(requestContext, "translate").mockImplementation( (message) => message ); - try { - const args: MutationCreateOrganizationArgs = { - data: { - description: "description", - name: "random", - userRegistrationRequired: true, - visibleInSearch: true, - apiUrl: "apiUrl", - location: - "JWQPfpdkGGGKyryb86K4YN85nDj4m4F7gEAMBbMXLax73pn2okV6kpWY0EYO0XSlUc0fAlp45UCgg3s6mqsRYF9FOlzNIDFLZ1rd03Z17cdJRuvBcAmbC0imyqGdXHGDUQmVyOjDkaOLAvjhB5uDeuEqajcAPTcKpZ6LMpigXuqRAd0xGdPNXyITC03FEeKZAjjJL35cSIUeMv5eWmiFlmmm70FU1Bp6575zzBtEdyWPLflcA2GpGmmf4zvT7nfgN3NIkwQIhk9OwP8dn75YYczcYuUzLpxBu1Lyog77YlAj5DNdTIveXu9zHeC6V4EEUcPQtf1622mhdU3jZNMIAyxcAG4ErtztYYRqFs0ApUxXiQI38rmiaLcicYQgcOxpmFvqRGiSduiCprCYm90CHWbQFq4w2uhr8HhR3r9HYMIYtrRyO6C3rPXaQ7otpjuNgE0AKI57AZ4nGG1lvNwptFCY60JEndSLX9Za6XP1zkVRLaMZArQNl", - }, - file: null, - }; - const context = { - userId: testUser?._id, - }; - await createOrganizationResolver?.({}, args, context); - } catch (error: any) { - expect(error.message).toEqual( - `${LENGTH_VALIDATION_ERROR.MESSAGE} 50 characters in location` + const invalidAddress = { + // Constructing an invalid address. + city: "", // An empty city field + countryCode: "USA", // Invalid country code format + dependentLocality: "Manhattan", + line1: "123 Main Street", + line2: "Apt 2B", + postalCode: "InvalidPostalCode", // Invalid postal code format + sortingCode: "ABC123", + state: "New York", + }; + + const validAddress = { + city: "New York", + countryCode: "US", + dependentLocality: "Manhattan", + line1: "123 Main Street", + line2: "Apt 2B", + postalCode: "10001", + sortingCode: "ABC123", + state: "NY", + }; + + const invalidArgs: MutationCreateOrganizationArgs = { + data: { + description: "Some description", + name: "Test Organization", + visibleInSearch: true, + apiUrl: "https://example.com/api", + address: invalidAddress, + }, + file: null, + }; + + const validArgs: MutationCreateOrganizationArgs = { + data: { + description: "Some description", + name: "Test Organization", + visibleInSearch: true, + apiUrl: "https://example.com/api", + address: validAddress, + }, + file: null, + }; + + const context = { + userId: testUser?._id, + }; + + if (createOrganizationResolver) { + // Testing for Invalid address + try { + await createOrganizationResolver({}, invalidArgs, context); + } catch (error: any) { + // Validate that the error message matches the expected Address Validation Error message + expect(error.message).toEqual("Not a Valid Address"); + } + + //Testing for Valid address + try { + await createOrganizationResolver({}, validArgs, context); + } catch (error: any) { + // Validate that the error message matches the expected Address Validation Error message + expect(error.message).toEqual("Something went wrong."); + } + } else { + console.error( + "Error: createOrganizationResolver is undefined in the test suite" + ); + } + }); + it("throws Address Validation Error for missing address", async () => { + const { requestContext } = await import("../../../src/libraries"); + vi.spyOn(requestContext, "translate").mockImplementation( + (message) => message + ); + + const missingAddress = {}; // No address field in the data + + const validArgs: MutationCreateOrganizationArgs = { + data: { + description: "Some description", + name: "Test Organization", + visibleInSearch: true, + apiUrl: "https://example.com/api", + address: missingAddress, + }, + file: null, + }; + + const context = { + userId: testUser?._id, + }; + + if (createOrganizationResolver) { + try { + await createOrganizationResolver({}, validArgs, context); + } catch (error: any) { + // Validate that the error message matches the expected Address Validation Error message + expect(error.message).toEqual("Not a Valid Address"); + } + } else { + console.error( + "Error: createOrganizationResolver is undefined in the test suite" ); } }); diff --git a/tests/resolvers/Mutation/removeOrganization.spec.ts b/tests/resolvers/Mutation/removeOrganization.spec.ts index 7839d5107a..267e6a0689 100644 --- a/tests/resolvers/Mutation/removeOrganization.spec.ts +++ b/tests/resolvers/Mutation/removeOrganization.spec.ts @@ -35,7 +35,7 @@ import { import { createTestUserFunc } from "../../helpers/user"; import type { TestUserType } from "../../helpers/userAndOrg"; import { cacheOrganizations } from "../../../src/services/OrganizationCache/cacheOrganizations"; - +/* eslint-disable */ let MONGOOSE_INSTANCE: typeof mongoose; let testUsers: TestUserType[]; let testOrganization: InterfaceOrganization & @@ -52,6 +52,15 @@ beforeAll(async () => { testOrganization = await Organization.create({ name: "name", description: "description", + address: { + countryCode: `US`, + city: `SAMPLE`, + dependentLocality: "TEST", + line1: "TEST", + postalCode: "110001", + sortingCode: "ABC-123", + state: "Delhi", + }, isPublic: true, creatorId: testUsers[0]?._id, admins: [testUsers[0]?._id], @@ -333,6 +342,15 @@ describe("resolvers -> Mutation -> removeOrganization", () => { const newTestOrganization = await Organization.create({ name: "name", description: "description", + address: { + countryCode: `US`, + city: `SAMPLE`, + dependentLocality: "TEST", + line1: "TEST", + postalCode: "110001", + sortingCode: "ABC-123", + state: "Delhi", + }, isPublic: true, creatorId: testUsers[0]?._id, admins: [testUsers[0]?._id], diff --git a/tests/resolvers/Mutation/removeOrganizationImage.spec.ts b/tests/resolvers/Mutation/removeOrganizationImage.spec.ts index f483126134..af6c1b1bd7 100644 --- a/tests/resolvers/Mutation/removeOrganizationImage.spec.ts +++ b/tests/resolvers/Mutation/removeOrganizationImage.spec.ts @@ -30,7 +30,7 @@ let MONGOOSE_INSTANCE: typeof mongoose; let testUser: TestUserType; let testAdminUser: TestUserType; let testOrganization: TestOrganizationType; - +/* eslint-disable */ beforeAll(async () => { MONGOOSE_INSTANCE = await connect(); @@ -41,6 +41,15 @@ beforeAll(async () => { testOrganization = await Organization.create({ name: "name", description: "description", + address: { + countryCode: `US`, + city: `SAMPLE`, + dependentLocality: "TEST", + line1: "TES", + postalCode: "110001", + sortingCode: "ABC-123", + state: "Delhi", + }, isPublic: true, admins: [testAdminUser?._id], creatorId: testAdminUser?._id, diff --git a/tests/resolvers/Mutation/removeSampleOrganization.spec.ts b/tests/resolvers/Mutation/removeSampleOrganization.spec.ts index 00da17a0df..cc5030b597 100644 --- a/tests/resolvers/Mutation/removeSampleOrganization.spec.ts +++ b/tests/resolvers/Mutation/removeSampleOrganization.spec.ts @@ -11,7 +11,7 @@ import { USER_NOT_AUTHORIZED_ERROR, USER_NOT_FOUND_ERROR, } from "../../../src/constants"; - +/* eslint-disable */ const ORGANIZATION_ID = ((): InterfaceOrganization & mongoose.Document => { const _id = faker.database.mongodbObjectId(); @@ -20,7 +20,6 @@ const ORGANIZATION_ID = ((): InterfaceOrganization & _id, name: faker.company.name(), description: faker.lorem.sentences(), - location: `${faker.location.country()}, ${faker.location.city()}`, isPublic: true, creatorId: creatorId, status: "ACTIVE", @@ -90,7 +89,6 @@ describe("Remove Sample Organization Resolver - User Authorization", async () => _id, name: faker.company.name(), description: faker.lorem.sentences(), - location: `${faker.location.country()}, ${faker.location.city()}`, isPublic: true, creatorId: creatorId, status: "ACTIVE", @@ -145,7 +143,6 @@ describe("Remove Sample Organization Resolver - User Authorization", async () => _id, name: faker.company.name(), description: faker.lorem.sentences(), - location: `${faker.location.country()}, ${faker.location.city()}`, isPublic: true, creatorId: creatorId, status: "ACTIVE",