From c5ce9429e9a3b848365f4bbefdd8be42bd0ecff8 Mon Sep 17 00:00:00 2001 From: Anubhav Banerjee Date: Mon, 8 Jan 2024 19:23:03 +0530 Subject: [PATCH 01/19] Made changes to the Organization location parameter in both types and mutations --- schema.graphql | 4 +- src/models/Organization.ts | 40 +++++++++- src/resolvers/Mutation/createOrganization.ts | 79 ++++++++++++++++--- src/typeDefs/inputs.ts | 2 +- src/typeDefs/types.ts | 2 +- src/types/generatedGraphQLTypes.ts | 6 +- .../Mutation/createOrganization.spec.ts | 78 ++++++++++++++++-- 7 files changed, 180 insertions(+), 31 deletions(-) diff --git a/schema.graphql b/schema.graphql index 80b0f9cf37..be173fa9fe 100644 --- a/schema.graphql +++ b/schema.graphql @@ -564,6 +564,7 @@ input OTPInput { type Organization { _id: ID! + address: Address admins(adminId: ID): [User] apiUrl: URL! blockedUsers: [User] @@ -573,7 +574,6 @@ type Organization { description: String! image: String isPublic: Boolean! - location: String members: [User] membershipRequests: [MembershipRequest] name: String! @@ -601,12 +601,12 @@ type OrganizationInfoNode { } input OrganizationInput { + address: AddressInput apiUrl: URL attendees: String description: String! image: String isPublic: Boolean! - location: String name: String! visibleInSearch: Boolean! } diff --git a/src/models/Organization.ts b/src/models/Organization.ts index a1487a2b8c..b420ce6412 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; + }; isPublic: boolean; creator: PopulatedDoc; status: string; @@ -35,7 +44,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 isPublic - Organization visibility. * @param creator - Organization creator, referring to `User` model. * @param status - Status. @@ -63,8 +72,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, + }, }, isPublic: { type: Boolean, diff --git a/src/resolvers/Mutation/createOrganization.ts b/src/resolvers/Mutation/createOrganization.ts index 20e57afca0..607ae0e287 100644 --- a/src/resolvers/Mutation/createOrganization.ts +++ b/src/resolvers/Mutation/createOrganization.ts @@ -1,5 +1,5 @@ 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 +39,14 @@ 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 && args.data?.address) { validationResultName = isValidString(args.data?.name, 256); validationResultDescription = isValidString(args.data?.description, 500); - validationResultLocation = isValidString(args.data?.location, 50); + validationResultAddress = validateAddress(args.data?.address); } if (!validationResultName.isLessThanMaxLength) { @@ -65,18 +65,14 @@ 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, creator: context.userId, admins: [context.userId], @@ -105,3 +101,62 @@ 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; + + const isCityValid = !!city && city.length > 0; + + // It should be a valid country code. + const isCountryCodeValid = !!countryCode && countryCode.length === 2; // Assuming country code is a 2-letter string + + // It should exist and have a length greater than 0 + const isDependentLocalityValid = + !!dependentLocality && dependentLocality.length > 0; + + // Line 1 should exist and have a length greater than 0 + const isLine1Valid = !!line1 && line1.length > 0; + + // Line 2 should exist and have a length greater than 0 + const isLine2Valid = !!line2 && line2.length > 0; + + // It should exist and have a valid format. + const isPostalCodeValid = !!postalCode && /^\d+$/.test(postalCode); + + // It should exist and have a valid format based on your criteria + const isSortingCodeValid = !!sortingCode && sortingCode.length > 0; // Assuming a specific format or requirement + + // It should exist and have a length greater than 0 + const isStateValid = !!state && state.length > 0; + + const isAddressValid = + isCityValid && + isCountryCodeValid && + isDependentLocalityValid && + isLine1Valid && + isLine2Valid && + isPostalCodeValid && + isSortingCodeValid && + isStateValid; + + return { isAddressValid }; +} diff --git a/src/typeDefs/inputs.ts b/src/typeDefs/inputs.ts index 40763e6904..7cd959eb6b 100644 --- a/src/typeDefs/inputs.ts +++ b/src/typeDefs/inputs.ts @@ -144,7 +144,7 @@ export const inputs = gql` input OrganizationInput { name: String! description: String! - location: String + address: AddressInput attendees: String isPublic: Boolean! visibleInSearch: Boolean! diff --git a/src/typeDefs/types.ts b/src/typeDefs/types.ts index b8a001493b..f93e6396e7 100644 --- a/src/typeDefs/types.ts +++ b/src/typeDefs/types.ts @@ -209,7 +209,7 @@ export const types = gql` _id: ID! name: String! description: String! - location: String + address: Address isPublic: Boolean! creator: User! members: [User] diff --git a/src/types/generatedGraphQLTypes.ts b/src/types/generatedGraphQLTypes.ts index a4ef88a403..91605e4487 100644 --- a/src/types/generatedGraphQLTypes.ts +++ b/src/types/generatedGraphQLTypes.ts @@ -1107,6 +1107,7 @@ export type OtpInput = { export type Organization = { __typename?: 'Organization'; _id: Scalars['ID']; + address?: Maybe
; admins?: Maybe>>; apiUrl: Scalars['URL']; blockedUsers?: Maybe>>; @@ -1116,7 +1117,6 @@ export type Organization = { description: Scalars['String']; image?: Maybe; isPublic: Scalars['Boolean']; - location?: Maybe; members?: Maybe>>; membershipRequests?: Maybe>>; name: Scalars['String']; @@ -1159,12 +1159,12 @@ export type OrganizationInfoNode = { }; export type OrganizationInput = { + address?: InputMaybe; apiUrl?: InputMaybe; attendees?: InputMaybe; description: Scalars['String']; image?: InputMaybe; isPublic: Scalars['Boolean']; - location?: InputMaybe; name: Scalars['String']; visibleInSearch: Scalars['Boolean']; }; @@ -2661,6 +2661,7 @@ export type MutationResolvers = { _id?: Resolver; + address?: Resolver, ParentType, ContextType>; admins?: Resolver>>, ParentType, ContextType, Partial>; apiUrl?: Resolver; blockedUsers?: Resolver>>, ParentType, ContextType>; @@ -2670,7 +2671,6 @@ export type OrganizationResolvers; image?: Resolver, ParentType, ContextType>; isPublic?: Resolver; - location?: Resolver, ParentType, ContextType>; members?: Resolver>>, ParentType, ContextType>; membershipRequests?: Resolver>>, ParentType, ContextType>; name?: Resolver; diff --git a/tests/resolvers/Mutation/createOrganization.spec.ts b/tests/resolvers/Mutation/createOrganization.spec.ts index f200b8fa36..304ef835fc 100644 --- a/tests/resolvers/Mutation/createOrganization.spec.ts +++ b/tests/resolvers/Mutation/createOrganization.spec.ts @@ -58,7 +58,16 @@ describe("resolvers -> Mutation -> createOrganization", () => { name: "name", visibleInSearch: true, apiUrl: "apiUrl", - location: "location", + address: { + city: "CityName", + countryCode: "CountryCode", + dependentLocality: "Dependent Locality", + line1: "123 Main Street", + line2: "Apartment 456", + postalCode: "12345", + sortingCode: "ABC-123", + state: "State/Province", + }, }, }; @@ -109,7 +118,16 @@ describe("resolvers -> Mutation -> createOrganization", () => { name: "name", visibleInSearch: true, apiUrl: "apiUrl", - location: "location", + address: { + city: "CityName", + countryCode: "CountryCode", + dependentLocality: "Dependent Locality", + line1: "123 Main Street", + line2: "Apartment 456", + postalCode: "12345", + sortingCode: "ABC-123", + state: "State/Province", + }, }, file: "imagePath", }; @@ -166,7 +184,16 @@ describe("resolvers -> Mutation -> createOrganization", () => { name: "name", visibleInSearch: true, apiUrl: "apiUrl", - location: "location", + address: { + city: "CityName", + countryCode: "CountryCode", + dependentLocality: "Dependent Locality", + line1: "123 Main Street", + line2: "Apartment 456", + postalCode: "12345", + sortingCode: "ABC-123", + state: "State/Province", + }, }, file: null, }; @@ -186,7 +213,16 @@ describe("resolvers -> Mutation -> createOrganization", () => { name: "name", visibleInSearch: true, apiUrl: "apiUrl", - location: "location", + address: { + city: "CityName", + countryCode: "CountryCode", + dependentLocality: "Dependent Locality", + line1: "123 Main Street", + line2: "Apartment 456", + postalCode: "12345", + sortingCode: "ABC-123", + state: "State/Province", + }, creator: testUser?._id, admins: [testUser?._id], members: [testUser?._id], @@ -208,7 +244,16 @@ describe("resolvers -> Mutation -> createOrganization", () => { name: "JWQPfpdkGGGKyryb86K4YN85nDj4m4F7gEAMBbMXLax73pn2okV6kpWY0EYO0XSlUc0fAlp45UCgg3s6mqsRYF9FOlzNIDFLZ1rd03Z17cdJRuvBcAmbC0imyqGdXHGDUQmVyOjDkaOLAvjhB5uDeuEqajcAPTcKpZ6LMpigXuqRAd0xGdPNXyITC03FEeKZAjjJL35cSIUeMv5eWmiFlmmm70FU1Bp6575zzBtEdyWPLflcA2GpGmmf4zvT7nfgN3NIkwQIhk9OwP8dn75YYczcYuUzLpxBu1Lyog77YlAj5DNdTIveXu9zHeC6V4EEUcPQtf1622mhdU3jZNMIAyxcAG4ErtztYYRqFs0ApUxXiQI38rmiaLcicYQgcOxpmFvqRGiSduiCprCYm90CHWbQFq4w2uhr8HhR3r9HYMIYtrRyO6C3rPXaQ7otpjuNgE0AKI57AZ4nGG1lvNwptFCY60JEndSLX9Za6XP1zkVRLaMZArQNl", visibleInSearch: true, apiUrl: "apiUrl", - location: "location", + address: { + city: "CityName", + countryCode: "CountryCode", + dependentLocality: "Dependent Locality", + line1: "123 Main Street", + line2: "Apartment 456", + postalCode: "12345", + sortingCode: "ABC-123", + state: "State/Province", + }, }, file: null, }; @@ -237,7 +282,16 @@ describe("resolvers -> Mutation -> createOrganization", () => { name: "random", visibleInSearch: true, apiUrl: "apiUrl", - location: "location", + address: { + city: "CityName", + countryCode: "CountryCode", + dependentLocality: "Dependent Locality", + line1: "123 Main Street", + line2: "Apartment 456", + postalCode: "12345", + sortingCode: "ABC-123", + state: "State/Province", + }, }, file: null, }; @@ -265,8 +319,16 @@ describe("resolvers -> Mutation -> createOrganization", () => { name: "random", visibleInSearch: true, apiUrl: "apiUrl", - location: - "JWQPfpdkGGGKyryb86K4YN85nDj4m4F7gEAMBbMXLax73pn2okV6kpWY0EYO0XSlUc0fAlp45UCgg3s6mqsRYF9FOlzNIDFLZ1rd03Z17cdJRuvBcAmbC0imyqGdXHGDUQmVyOjDkaOLAvjhB5uDeuEqajcAPTcKpZ6LMpigXuqRAd0xGdPNXyITC03FEeKZAjjJL35cSIUeMv5eWmiFlmmm70FU1Bp6575zzBtEdyWPLflcA2GpGmmf4zvT7nfgN3NIkwQIhk9OwP8dn75YYczcYuUzLpxBu1Lyog77YlAj5DNdTIveXu9zHeC6V4EEUcPQtf1622mhdU3jZNMIAyxcAG4ErtztYYRqFs0ApUxXiQI38rmiaLcicYQgcOxpmFvqRGiSduiCprCYm90CHWbQFq4w2uhr8HhR3r9HYMIYtrRyO6C3rPXaQ7otpjuNgE0AKI57AZ4nGG1lvNwptFCY60JEndSLX9Za6XP1zkVRLaMZArQNl", + address: { + city: "CityName", + countryCode: "CountryCode", + dependentLocality: "Dependent Locality", + line1: "123 Main Street", + line2: "Apartment 456", + postalCode: "12345", + sortingCode: "ABC-123", + state: "State/Province", + }, }, file: null, }; From 1702d25462109f9de5506ff74c440f6da74ea83c Mon Sep 17 00:00:00 2001 From: Anubhav Banerjee Date: Wed, 10 Jan 2024 18:45:35 +0530 Subject: [PATCH 02/19] Added tests for the changes --- images/Zv9ATIFAoimage.png | Bin 0 -> 132 bytes src/resolvers/Mutation/createOrganization.ts | 5 +- .../Mutation/createOrganization.spec.ts | 110 +++++++++++++----- 3 files changed, 84 insertions(+), 31 deletions(-) create mode 100644 images/Zv9ATIFAoimage.png diff --git a/images/Zv9ATIFAoimage.png b/images/Zv9ATIFAoimage.png new file mode 100644 index 0000000000000000000000000000000000000000..e22d4f1a3c5333c68bc4e05fbdad02cfffe317dc GIT binary patch literal 132 zcmeAS@N?(olHy`uVBq!ia0vp^Od!m`1|*BN@u~nR#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=DinK$vl=HlH+5P}0-IF+?If*{1l}nR+&bgvw7(IGLrTrI{Jr XQ`poMzO&r|Dq`?-^>bP0l+XkKyptXN literal 0 HcmV?d00001 diff --git a/src/resolvers/Mutation/createOrganization.ts b/src/resolvers/Mutation/createOrganization.ts index 607ae0e287..0f814c5354 100644 --- a/src/resolvers/Mutation/createOrganization.ts +++ b/src/resolvers/Mutation/createOrganization.ts @@ -1,5 +1,8 @@ import "dotenv/config"; -import type { MutationResolvers , Address } 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"; diff --git a/tests/resolvers/Mutation/createOrganization.spec.ts b/tests/resolvers/Mutation/createOrganization.spec.ts index 304ef835fc..d9a71248e2 100644 --- a/tests/resolvers/Mutation/createOrganization.spec.ts +++ b/tests/resolvers/Mutation/createOrganization.spec.ts @@ -147,7 +147,16 @@ describe("resolvers -> Mutation -> createOrganization", () => { name: "name", visibleInSearch: true, apiUrl: "apiUrl", - location: "location", + address: { + city: "CityName", + countryCode: "CountryCode", + dependentLocality: "Dependent Locality", + line1: "123 Main Street", + line2: "Apartment 456", + postalCode: "12345", + sortingCode: "ABC-123", + state: "State/Province", + }, creator: testUser?._id, admins: [testUser?._id], members: [testUser?._id], @@ -306,40 +315,81 @@ 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", - isPublic: true, - name: "random", - visibleInSearch: true, - apiUrl: "apiUrl", - address: { - city: "CityName", - countryCode: "CountryCode", - dependentLocality: "Dependent Locality", - line1: "123 Main Street", - line2: "Apartment 456", - postalCode: "12345", - sortingCode: "ABC-123", - state: "State/Province", - }, - }, - file: null, - }; - const context = { - userId: testUser?._id, - }; + 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", + }; - await createOrganizationResolver?.({}, args, context); - } catch (error: any) { - expect(error.message).toEqual( - `${LENGTH_VALIDATION_ERROR.MESSAGE} 50 characters in location` + 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", + isPublic: true, + name: "Test Organization", + visibleInSearch: true, + apiUrl: "https://example.com/api", + address: invalidAddress, + }, + file: null, + }; + + const validArgs: MutationCreateOrganizationArgs = { + data: { + description: "Some description", + isPublic: true, + 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("Invalid Address Provided"); + } + + //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" ); } }); From 19b4192e0a345a79891f0e123d86f07359ba9983 Mon Sep 17 00:00:00 2001 From: Anubhav Banerjee Date: Wed, 10 Jan 2024 19:11:17 +0530 Subject: [PATCH 03/19] Changed sample data --- sample_data/organizations.json | 70 ++-------------------------------- 1 file changed, 4 insertions(+), 66 deletions(-) diff --git a/sample_data/organizations.json b/sample_data/organizations.json index 98028d41c9..1f5235f68d 100644 --- a/sample_data/organizations.json +++ b/sample_data/organizations.json @@ -11,72 +11,10 @@ "blockedUsers": [], "name": "The Unity Foundation", "description": "A foundation aimed at uniting the world and making it a better place for all.", - "location": "Delhi, India", - "isPublic": true, - "visibleInSearch": true, - "image": null, - "creator": "64378abd85008f171cf2990d", - "createdAt": "2023-04-13T05:16:52.827Z", - "__v": 0 - }, - { - "_id": "6537904485008f171cf29924", - "status": "ACTIVE", - "members": [ - "65378abd85008f171cf2990d", - "67378abd85008f171cf2991d", - "67378abd85008f171cf2992d", - "67378abd85008f171cf2993d" - ], - "admins": ["65378abd85008f171cf2990d"], - "groupChats": [], - "posts": [], - "pinnedPosts": [], - "membershipRequests": [], - "blockedUsers": [], - "name": "Angel Foundation", - "description": "We are aimed at improving the education spaces for the under privileged girl child.", - "location": "Kolkata, West Bengal", - "isPublic": true, - "visibleInSearch": true, - "image": null, - "creator": "64378abd85008f171cf2990d", - "createdAt": "2023-04-13T05:16:52.827Z", - "__v": 0 - }, - { - "_id": "6637904485008f171cf29924", - "status": "ACTIVE", - "members": ["66378abd85008f171cf2990d"], - "admins": ["66378abd85008f171cf2990d"], - "groupChats": [], - "posts": [], - "pinnedPosts": [], - "membershipRequests": [], - "blockedUsers": [], - "name": "Hope Foundation", - "description": "A place where money and power doesn't matter. Free legal aid to everyone.", - "location": "Mountain View, CA", - "isPublic": true, - "visibleInSearch": true, - "image": null, - "creator": "64378abd85008f171cf2990d", - "createdAt": "2023-04-13T05:16:52.827Z", - "__v": 0 - }, - { - "_id": "6737904485008f171cf29924", - "status": "ACTIVE", - "members": ["67378abd85008f171cf2990d"], - "admins": ["67378abd85008f171cf2990d"], - "groupChats": [], - "posts": [], - "pinnedPosts": [], - "membershipRequests": [], - "blockedUsers": [], - "name": "Dignity Foundation", - "description": "A foundation aimed at improving the lives of old age citizens.", - "location": "Brooklyn, NYC", + "address": { + "city": "Delhi", + "state": "Delhi" + }, "isPublic": true, "visibleInSearch": true, "image": null, From e93673b76335586ed1bd5a2351dd1678d2641b48 Mon Sep 17 00:00:00 2001 From: Anubhav Banerjee Date: Wed, 10 Jan 2024 20:15:49 +0530 Subject: [PATCH 04/19] Changed data in sample_data --- images/Zv9ATIFAoimage.png | Bin 132 -> 0 bytes sample_data/organizations.json | 6 ++++++ 2 files changed, 6 insertions(+) delete mode 100644 images/Zv9ATIFAoimage.png diff --git a/images/Zv9ATIFAoimage.png b/images/Zv9ATIFAoimage.png deleted file mode 100644 index e22d4f1a3c5333c68bc4e05fbdad02cfffe317dc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 132 zcmeAS@N?(olHy`uVBq!ia0vp^Od!m`1|*BN@u~nR#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=DinK$vl=HlH+5P}0-IF+?If*{1l}nR+&bgvw7(IGLrTrI{Jr XQ`poMzO&r|Dq`?-^>bP0l+XkKyptXN diff --git a/sample_data/organizations.json b/sample_data/organizations.json index 1f5235f68d..8308069d0b 100644 --- a/sample_data/organizations.json +++ b/sample_data/organizations.json @@ -13,6 +13,12 @@ "description": "A foundation aimed at uniting the world and making it a better place for all.", "address": { "city": "Delhi", + "countryCode": "IN", + "dependentLocality": "Some Dependent Locality", + "line1": "123 Random Street", + "line2": "Apartment 456", + "postalCode": "110001", + "sortingCode": "ABC-123", "state": "Delhi" }, "isPublic": true, From 0efb2796fbeed3f244c08a8a721e562246ef1be0 Mon Sep 17 00:00:00 2001 From: Anubhav Banerjee Date: Fri, 12 Jan 2024 19:13:16 +0530 Subject: [PATCH 05/19] Fixed the failing tests --- .../Mutation/createOrganization.spec.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/resolvers/Mutation/createOrganization.spec.ts b/tests/resolvers/Mutation/createOrganization.spec.ts index d9a71248e2..47555cd86f 100644 --- a/tests/resolvers/Mutation/createOrganization.spec.ts +++ b/tests/resolvers/Mutation/createOrganization.spec.ts @@ -60,7 +60,7 @@ describe("resolvers -> Mutation -> createOrganization", () => { apiUrl: "apiUrl", address: { city: "CityName", - countryCode: "CountryCode", + countryCode: "US", dependentLocality: "Dependent Locality", line1: "123 Main Street", line2: "Apartment 456", @@ -120,7 +120,7 @@ describe("resolvers -> Mutation -> createOrganization", () => { apiUrl: "apiUrl", address: { city: "CityName", - countryCode: "CountryCode", + countryCode: "US", dependentLocality: "Dependent Locality", line1: "123 Main Street", line2: "Apartment 456", @@ -149,7 +149,7 @@ describe("resolvers -> Mutation -> createOrganization", () => { apiUrl: "apiUrl", address: { city: "CityName", - countryCode: "CountryCode", + countryCode: "US", dependentLocality: "Dependent Locality", line1: "123 Main Street", line2: "Apartment 456", @@ -195,7 +195,7 @@ describe("resolvers -> Mutation -> createOrganization", () => { apiUrl: "apiUrl", address: { city: "CityName", - countryCode: "CountryCode", + countryCode: "US", dependentLocality: "Dependent Locality", line1: "123 Main Street", line2: "Apartment 456", @@ -224,7 +224,7 @@ describe("resolvers -> Mutation -> createOrganization", () => { apiUrl: "apiUrl", address: { city: "CityName", - countryCode: "CountryCode", + countryCode: "US", dependentLocality: "Dependent Locality", line1: "123 Main Street", line2: "Apartment 456", @@ -255,7 +255,7 @@ describe("resolvers -> Mutation -> createOrganization", () => { apiUrl: "apiUrl", address: { city: "CityName", - countryCode: "CountryCode", + countryCode: "US", dependentLocality: "Dependent Locality", line1: "123 Main Street", line2: "Apartment 456", @@ -293,7 +293,7 @@ describe("resolvers -> Mutation -> createOrganization", () => { apiUrl: "apiUrl", address: { city: "CityName", - countryCode: "CountryCode", + countryCode: "US", dependentLocality: "Dependent Locality", line1: "123 Main Street", line2: "Apartment 456", @@ -377,7 +377,7 @@ describe("resolvers -> Mutation -> createOrganization", () => { await createOrganizationResolver({}, invalidArgs, context); } catch (error: any) { // Validate that the error message matches the expected Address Validation Error message - expect(error.message).toEqual("Invalid Address Provided"); + expect(error.message).toEqual("Not a Valid Address"); } //Testing for Valid address From d6ff9368a76eb02acc9e9f4eb0c16b176de11b61 Mon Sep 17 00:00:00 2001 From: Anubhav Banerjee Date: Sat, 13 Jan 2024 13:51:15 +0530 Subject: [PATCH 06/19] Fixed linting issues --- package-lock.json | 8 -------- schema.graphql | 1 - src/types/generatedGraphQLTypes.ts | 5 ++--- tests/resolvers/Mutation/createOrganization.spec.ts | 4 +--- 4 files changed, 3 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 56254b5f1e..388a35a720 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9587,14 +9587,6 @@ "node": ">= 4" } }, - "node_modules/generic-pool": { - "version": "3.9.0", - "resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-3.9.0.tgz", - "integrity": "sha512-hymDOu5B53XvN4QT9dBmZxPX4CWhBPPLguTZ9MMFeFa/Kg0xWVfylOVNlJji/E7yTZWFd/q9GO5TxDLq156D7g==", - "engines": { - "node": ">= 4" - } - }, "node_modules/gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", diff --git a/schema.graphql b/schema.graphql index c983106c40..81490aac51 100644 --- a/schema.graphql +++ b/schema.graphql @@ -585,7 +585,6 @@ input OrganizationInput { attendees: String description: String! image: String - isPublic: Boolean! name: String! userRegistrationRequired: Boolean visibleInSearch: Boolean diff --git a/src/types/generatedGraphQLTypes.ts b/src/types/generatedGraphQLTypes.ts index d1ff4d6d53..d0a29f1072 100644 --- a/src/types/generatedGraphQLTypes.ts +++ b/src/types/generatedGraphQLTypes.ts @@ -1044,17 +1044,17 @@ export type OtpInput = { export type Organization = { __typename?: 'Organization'; - address?: Maybe
; _id: Scalars['ID']['output']; + address?: Maybe
; admins?: Maybe>>; apiUrl: Scalars['URL']['output']; blockedUsers?: Maybe>>; createdAt?: Maybe; creator: User; customFields: Array; - isPublic: Scalars['Boolean']; description: Scalars['String']['output']; image?: Maybe; + isPublic: Scalars['Boolean']['output']; members?: Maybe>>; membershipRequests?: Maybe>>; name: Scalars['String']['output']; @@ -1103,7 +1103,6 @@ export type OrganizationInput = { attendees?: InputMaybe; description: Scalars['String']['input']; image?: InputMaybe; - location?: InputMaybe; name: Scalars['String']['input']; userRegistrationRequired?: InputMaybe; visibleInSearch?: InputMaybe; diff --git a/tests/resolvers/Mutation/createOrganization.spec.ts b/tests/resolvers/Mutation/createOrganization.spec.ts index 190f0107dd..37c5d4bc6c 100644 --- a/tests/resolvers/Mutation/createOrganization.spec.ts +++ b/tests/resolvers/Mutation/createOrganization.spec.ts @@ -332,7 +332,7 @@ describe("resolvers -> Mutation -> createOrganization", () => { sortingCode: "ABC123", state: "New York", }; - + const validAddress = { city: "New York", countryCode: "US", @@ -347,7 +347,6 @@ describe("resolvers -> Mutation -> createOrganization", () => { const invalidArgs: MutationCreateOrganizationArgs = { data: { description: "Some description", - isPublic: true, name: "Test Organization", visibleInSearch: true, apiUrl: "https://example.com/api", @@ -359,7 +358,6 @@ describe("resolvers -> Mutation -> createOrganization", () => { const validArgs: MutationCreateOrganizationArgs = { data: { description: "Some description", - isPublic: true, name: "Test Organization", visibleInSearch: true, apiUrl: "https://example.com/api", From 0643cc640cfec869c443a11d0098ef98f39dc94b Mon Sep 17 00:00:00 2001 From: Anubhav Banerjee Date: Sat, 13 Jan 2024 19:54:23 +0530 Subject: [PATCH 07/19] Added extra tests --- src/resolvers/Mutation/createOrganization.ts | 5 ++- .../Mutation/createOrganization.spec.ts | 35 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/resolvers/Mutation/createOrganization.ts b/src/resolvers/Mutation/createOrganization.ts index 0f814c5354..5124ab5926 100644 --- a/src/resolvers/Mutation/createOrganization.ts +++ b/src/resolvers/Mutation/createOrganization.ts @@ -46,9 +46,12 @@ export const createOrganization: MutationResolvers["createOrganization"] = isAddressValid: false, }; - if (args.data?.name && args.data?.description && args.data?.address) { + if (args.data?.name && args.data?.description) { validationResultName = isValidString(args.data?.name, 256); validationResultDescription = isValidString(args.data?.description, 500); + } + + if (args.data?.address) { validationResultAddress = validateAddress(args.data?.address); } diff --git a/tests/resolvers/Mutation/createOrganization.spec.ts b/tests/resolvers/Mutation/createOrganization.spec.ts index 37c5d4bc6c..dc8e89f973 100644 --- a/tests/resolvers/Mutation/createOrganization.spec.ts +++ b/tests/resolvers/Mutation/createOrganization.spec.ts @@ -392,4 +392,39 @@ describe("resolvers -> Mutation -> createOrganization", () => { ); } }); + it("throws Address Validation Error for missing address", async () => { + const { requestContext } = await import("../../../src/libraries"); + vi.spyOn(requestContext, "translate").mockImplementation( + (message) => message + ); + + const missingAddress = undefined; // No address field in the data + + const validArgs: MutationCreateOrganizationArgs = { + data: { + description: "Some description", + name: "Test Organization", + visibleInSearch: true, + apiUrl: "https://example.com/api", + }, + 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" + ); + } + }); }); From a3adebe67c5474bb2dd7466f8fb42d765d7490a1 Mon Sep 17 00:00:00 2001 From: Anubhav Banerjee Date: Sat, 13 Jan 2024 20:00:49 +0530 Subject: [PATCH 08/19] Made address compulsory for organizations From d4b56d2e4518fb56c5188329f5f45d311b728d3c Mon Sep 17 00:00:00 2001 From: Anubhav Banerjee Date: Sat, 13 Jan 2024 20:15:19 +0530 Subject: [PATCH 09/19] Removed IsPublic param --- schema.graphql | 1 - src/models/Organization.ts | 1 - src/typeDefs/types.ts | 1 - src/types/generatedGraphQLTypes.ts | 2 -- 4 files changed, 5 deletions(-) diff --git a/schema.graphql b/schema.graphql index 81490aac51..062210a3e7 100644 --- a/schema.graphql +++ b/schema.graphql @@ -551,7 +551,6 @@ type Organization { customFields: [OrganizationCustomField!]! description: String! image: String - isPublic: Boolean! members: [User] membershipRequests: [MembershipRequest] name: String! diff --git a/src/models/Organization.ts b/src/models/Organization.ts index 41cffe65f3..681a8e6012 100644 --- a/src/models/Organization.ts +++ b/src/models/Organization.ts @@ -24,7 +24,6 @@ export interface InterfaceOrganization { sortingCode: string; state: string; }; - isPublic: boolean; creator: PopulatedDoc; status: string; members: PopulatedDoc[]; diff --git a/src/typeDefs/types.ts b/src/typeDefs/types.ts index 0840ea5ad9..1fccfe7f7d 100644 --- a/src/typeDefs/types.ts +++ b/src/typeDefs/types.ts @@ -201,7 +201,6 @@ export const types = gql` name: String! description: String! address: Address - isPublic: Boolean! creator: User! members: [User] admins(adminId: ID): [User] diff --git a/src/types/generatedGraphQLTypes.ts b/src/types/generatedGraphQLTypes.ts index d0a29f1072..3a212c5a35 100644 --- a/src/types/generatedGraphQLTypes.ts +++ b/src/types/generatedGraphQLTypes.ts @@ -1054,7 +1054,6 @@ export type Organization = { customFields: Array; description: Scalars['String']['output']; image?: Maybe; - isPublic: Scalars['Boolean']['output']; members?: Maybe>>; membershipRequests?: Maybe>>; name: Scalars['String']['output']; @@ -2547,7 +2546,6 @@ export type OrganizationResolvers, ParentType, ContextType>; description?: Resolver; image?: Resolver, ParentType, ContextType>; - isPublic?: Resolver; members?: Resolver>>, ParentType, ContextType>; membershipRequests?: Resolver>>, ParentType, ContextType>; name?: Resolver; From d2813b2d148a135833c5a2e3ab3504de611f96b6 Mon Sep 17 00:00:00 2001 From: Anubhav Banerjee Date: Sun, 14 Jan 2024 11:35:46 +0530 Subject: [PATCH 10/19] Made AddressInput Non-nullable --- schema.graphql | 2 +- src/typeDefs/inputs.ts | 2 +- src/types/generatedGraphQLTypes.ts | 6 +++--- tests/resolvers/Mutation/createOrganization.spec.ts | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/schema.graphql b/schema.graphql index 1ca015f787..8b8506d03f 100644 --- a/schema.graphql +++ b/schema.graphql @@ -601,7 +601,7 @@ type OrganizationInfoNode { } input OrganizationInput { - address: AddressInput + address: AddressInput! apiUrl: URL attendees: String description: String! diff --git a/src/typeDefs/inputs.ts b/src/typeDefs/inputs.ts index 1123e038c0..ba184c1c41 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! - address: AddressInput + address: AddressInput! attendees: String apiUrl: URL image: String diff --git a/src/types/generatedGraphQLTypes.ts b/src/types/generatedGraphQLTypes.ts index 59b9ecda3f..1a88fae5f4 100644 --- a/src/types/generatedGraphQLTypes.ts +++ b/src/types/generatedGraphQLTypes.ts @@ -1066,7 +1066,7 @@ export type OtpInput = { export type Organization = { __typename?: 'Organization'; _id: Scalars['ID']['output']; - address: Maybe
; + address?: Maybe
; admins?: Maybe>; apiUrl: Scalars['URL']['output']; blockedUsers?: Maybe>>; @@ -1119,7 +1119,7 @@ export type OrganizationInfoNode = { }; export type OrganizationInput = { - address?: InputMaybe; + address: AddressInput; apiUrl?: InputMaybe; attendees?: InputMaybe; description: Scalars['String']['input']; @@ -2582,7 +2582,7 @@ export type MutationResolvers = { _id?: Resolver; - address: Resolver, ParentType, ContextType>; + address?: Resolver, ParentType, ContextType>; admins?: Resolver>, ParentType, ContextType, Partial>; apiUrl?: Resolver; blockedUsers?: Resolver>>, ParentType, ContextType>; diff --git a/tests/resolvers/Mutation/createOrganization.spec.ts b/tests/resolvers/Mutation/createOrganization.spec.ts index 59be63fad6..abd2dc9725 100644 --- a/tests/resolvers/Mutation/createOrganization.spec.ts +++ b/tests/resolvers/Mutation/createOrganization.spec.ts @@ -398,7 +398,7 @@ describe("resolvers -> Mutation -> createOrganization", () => { (message) => message ); - const missingAddress = undefined; // No address field in the data + const missingAddress = {}; // No address field in the data const validArgs: MutationCreateOrganizationArgs = { data: { @@ -406,6 +406,7 @@ describe("resolvers -> Mutation -> createOrganization", () => { name: "Test Organization", visibleInSearch: true, apiUrl: "https://example.com/api", + address: missingAddress, }, file: null, }; From 3bd0140437366fc1ca90e6983cb7db050b3ea91f Mon Sep 17 00:00:00 2001 From: Anubhav Banerjee Date: Sun, 14 Jan 2024 20:01:17 +0530 Subject: [PATCH 11/19] Added address to sample organizations --- sample_data/organizations.json | 92 ++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/sample_data/organizations.json b/sample_data/organizations.json index 8308069d0b..3beb81a9d6 100644 --- a/sample_data/organizations.json +++ b/sample_data/organizations.json @@ -27,5 +27,97 @@ "creator": "64378abd85008f171cf2990d", "createdAt": "2023-04-13T05:16:52.827Z", "__v": 0 + }, + { + "_id": "6537904485008f171cf29924", + "status": "ACTIVE", + "members": [ + "65378abd85008f171cf2990d", + "67378abd85008f171cf2991d", + "67378abd85008f171cf2992d", + "67378abd85008f171cf2993d" + ], + "admins": ["65378abd85008f171cf2990d"], + "groupChats": [], + "posts": [], + "pinnedPosts": [], + "membershipRequests": [], + "blockedUsers": [], + "name": "Angel Foundation", + "description": "We are aimed at improving the education spaces for the under privileged girl child.", + "address": { + "city": "Kolkata", + "countryCode": "IN", + "dependentLocality": "Some Dependent Locality", + "line1": "line1", + "line2": "line2", + "postalCode": "711205", + "sortingCode": "ABC-124", + "state": "West Bengal" + }, + "isPublic": true, + "visibleInSearch": true, + "image": null, + "creator": "64378abd85008f171cf2990d", + "createdAt": "2023-04-13T05:16:52.827Z", + "__v": 0 + }, + { + "_id": "6637904485008f171cf29924", + "status": "ACTIVE", + "members": ["66378abd85008f171cf2990d"], + "admins": ["66378abd85008f171cf2990d"], + "groupChats": [], + "posts": [], + "pinnedPosts": [], + "membershipRequests": [], + "blockedUsers": [], + "name": "Hope Foundation", + "description": "A place where money and power doesn't matter. Free legal aid to everyone.", + "address": { + "city": "Mountain View", + "countryCode": "US", + "dependentLocality": "Some Dependent Locality", + "line1": "123 Main Street", + "line2": "Apt 456", + "postalCode": "94040", + "sortingCode": "XYZ-789", + "state": "CA" + }, + "isPublic": true, + "visibleInSearch": true, + "image": null, + "creator": "64378abd85008f171cf2990d", + "createdAt": "2023-04-13T05:16:52.827Z", + "__v": 0 + }, + { + "_id": "6737904485008f171cf29924", + "status": "ACTIVE", + "members": ["67378abd85008f171cf2990d"], + "admins": ["67378abd85008f171cf2990d"], + "groupChats": [], + "posts": [], + "pinnedPosts": [], + "membershipRequests": [], + "blockedUsers": [], + "name": "Dignity Foundation", + "description": "A foundation aimed at improving the lives of old age citizens.", + "address": { + "city": "Brooklyn", + "countryCode": "US", + "dependentLocality": "Sample Dependent Locality", + "line1": "123 Main Street", + "line2": "Apt 456", + "postalCode": "11234", + "sortingCode": "ABC-789", + "state": "NY" + }, + "isPublic": true, + "visibleInSearch": true, + "image": null, + "creator": "64378abd85008f171cf2990d", + "createdAt": "2023-04-13T05:16:52.827Z", + "__v": 0 } ] From 1757e0bd4079808ede9e2e6139ce8b1ad5997c75 Mon Sep 17 00:00:00 2001 From: Anubhav Banerjee Date: Sat, 20 Jan 2024 18:03:29 +0530 Subject: [PATCH 12/19] Updated createSampleOrg utility functions --- src/utilities/createSampleOrganizationUtil.ts | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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", From aedee07f363a565d6a5b57f8a9d13e6da7165498 Mon Sep 17 00:00:00 2001 From: Anubhav Banerjee Date: Mon, 22 Jan 2024 19:37:17 +0530 Subject: [PATCH 13/19] Changed countryCode type to string --- schema.graphql | 4 ++-- src/typeDefs/inputs.ts | 2 +- src/typeDefs/types.ts | 2 +- src/types/generatedGraphQLTypes.ts | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/schema.graphql b/schema.graphql index 4fd7e054cd..4b92695aa9 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 diff --git a/src/typeDefs/inputs.ts b/src/typeDefs/inputs.ts index b7092ef18d..9113f89936 100644 --- a/src/typeDefs/inputs.ts +++ b/src/typeDefs/inputs.ts @@ -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 e4d95b2e9b..8fb7fa16d9 100644 --- a/src/typeDefs/types.ts +++ b/src/typeDefs/types.ts @@ -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 5e2930530b..48c1dbe6cd 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; @@ -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>; From 161ce7cb2bde3884642fd4c4ae9a33cc7e2372b1 Mon Sep 17 00:00:00 2001 From: Anubhav Banerjee Date: Tue, 23 Jan 2024 18:40:36 +0530 Subject: [PATCH 14/19] Updated the inputType for UpdateOrganization Mutation --- schema.graphql | 2 +- src/resolvers/Mutation/createOrganization.ts | 4 ++-- src/typeDefs/inputs.ts | 2 +- src/types/generatedGraphQLTypes.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/schema.graphql b/schema.graphql index 4b92695aa9..bc8d557437 100644 --- a/schema.graphql +++ b/schema.graphql @@ -921,8 +921,8 @@ input UpdateEventInput { } input UpdateOrganizationInput { + address: AddressInput description: String - location: String name: String userRegistrationRequired: Boolean visibleInSearch: Boolean diff --git a/src/resolvers/Mutation/createOrganization.ts b/src/resolvers/Mutation/createOrganization.ts index a22dbc1446..dbd7b5794a 100644 --- a/src/resolvers/Mutation/createOrganization.ts +++ b/src/resolvers/Mutation/createOrganization.ts @@ -85,7 +85,7 @@ export const createOrganization: MutationResolvers["createOrganization"] = members: [context.userId], }); - await cacheOrganizations([createdOrganization.toObject()!]); + await cacheOrganizations([createdOrganization.toObject()]); /* Adds createdOrganization._id to joinedOrganizations, createdOrganizations @@ -133,7 +133,7 @@ function validateAddress(address: Address | undefined): { const isCityValid = !!city && city.length > 0; // It should be a valid country code. - const isCountryCodeValid = !!countryCode && countryCode.length === 2; // Assuming country code is a 2-letter string + const isCountryCodeValid = !!countryCode && countryCode.length >= 2; // Assuming country code is a 2-letter string // It should exist and have a length greater than 0 const isDependentLocalityValid = diff --git a/src/typeDefs/inputs.ts b/src/typeDefs/inputs.ts index 9113f89936..3c3af19e60 100644 --- a/src/typeDefs/inputs.ts +++ b/src/typeDefs/inputs.ts @@ -280,7 +280,7 @@ export const inputs = gql` input UpdateOrganizationInput { name: String description: String - location: String + address: AddressInput userRegistrationRequired: Boolean visibleInSearch: Boolean } diff --git a/src/types/generatedGraphQLTypes.ts b/src/types/generatedGraphQLTypes.ts index 48c1dbe6cd..41902b784e 100644 --- a/src/types/generatedGraphQLTypes.ts +++ b/src/types/generatedGraphQLTypes.ts @@ -1607,8 +1607,8 @@ export type UpdateEventInput = { }; export type UpdateOrganizationInput = { + address?: InputMaybe; description?: InputMaybe; - location?: InputMaybe; name?: InputMaybe; userRegistrationRequired?: InputMaybe; visibleInSearch?: InputMaybe; From e2cbeb8f843d1246c9b62163f965a8fcee3cf964 Mon Sep 17 00:00:00 2001 From: Anubhav Banerjee Date: Tue, 23 Jan 2024 19:20:14 +0530 Subject: [PATCH 15/19] Restored creatorId for sample organizations --- sample_data/organizations.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sample_data/organizations.json b/sample_data/organizations.json index e2b87faf9c..f57ceab8bb 100644 --- a/sample_data/organizations.json +++ b/sample_data/organizations.json @@ -24,7 +24,7 @@ "userRegistrationRequired": false, "visibleInSearch": true, "image": null, - "creator": "64378abd85008f171cf2990d", + "creatorId": "64378abd85008f171cf2990d", "createdAt": "2023-04-13T05:16:52.827Z", "__v": 0 }, @@ -58,7 +58,7 @@ "userRegistrationRequired": false, "visibleInSearch": true, "image": null, - "creator": "64378abd85008f171cf2990d", + "creatorId": "64378abd85008f171cf2990d", "createdAt": "2023-04-13T05:16:52.827Z", "__v": 0 }, @@ -87,7 +87,7 @@ "userRegistrationRequired": false, "visibleInSearch": true, "image": null, - "creator": "64378abd85008f171cf2990d", + "creatorId": "64378abd85008f171cf2990d", "createdAt": "2023-04-13T05:16:52.827Z", "__v": 0 }, @@ -116,7 +116,7 @@ "userRegistrationRequired": false, "visibleInSearch": true, "image": null, - "creator": "64378abd85008f171cf2990d", + "creatorId": "64378abd85008f171cf2990d", "createdAt": "2023-04-13T05:16:52.827Z", "__v": 0 } From 4be5e625626a4568b8b2bebc51f0a7b04638e496 Mon Sep 17 00:00:00 2001 From: Anubhav Banerjee Date: Tue, 23 Jan 2024 19:42:49 +0530 Subject: [PATCH 16/19] Made line2,and sortingcode optional in address --- src/resolvers/Mutation/createOrganization.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/resolvers/Mutation/createOrganization.ts b/src/resolvers/Mutation/createOrganization.ts index dbd7b5794a..b0fcc926f2 100644 --- a/src/resolvers/Mutation/createOrganization.ts +++ b/src/resolvers/Mutation/createOrganization.ts @@ -133,7 +133,7 @@ function validateAddress(address: Address | undefined): { const isCityValid = !!city && city.length > 0; // It should be a valid country code. - const isCountryCodeValid = !!countryCode && countryCode.length >= 2; // Assuming country code is a 2-letter string + const isCountryCodeValid = !!countryCode && countryCode.length >= 2; // It should exist and have a length greater than 0 const isDependentLocalityValid = @@ -142,14 +142,17 @@ function validateAddress(address: Address | undefined): { // Line 1 should exist and have a length greater than 0 const isLine1Valid = !!line1 && line1.length > 0; - // Line 2 should exist and have a length greater than 0 - const isLine2Valid = !!line2 && line2.length > 0; + //Optional + const isLine2Valid = + line2 === undefined || (typeof line2 === "string" && line2.length > 0); // It should exist and have a valid format. const isPostalCodeValid = !!postalCode && /^\d+$/.test(postalCode); - // It should exist and have a valid format based on your criteria - const isSortingCodeValid = !!sortingCode && sortingCode.length > 0; // Assuming a specific format or requirement + //Optional + const isSortingCodeValid = + sortingCode === undefined || + (typeof sortingCode === "string" && sortingCode.length > 0); // It should exist and have a length greater than 0 const isStateValid = !!state && state.length > 0; @@ -164,5 +167,5 @@ function validateAddress(address: Address | undefined): { isSortingCodeValid && isStateValid; - return { isAddressValid }; + return { isAddressValid: isAddressValid }; } From c3a62646218ac1dbedc18bbc67b7b8a0a198f063 Mon Sep 17 00:00:00 2001 From: Anubhav Banerjee Date: Thu, 25 Jan 2024 23:20:40 +0530 Subject: [PATCH 17/19] Made countrycode and city mandatory fields, rest optional --- src/models/Organization.ts | 2 ++ src/resolvers/Mutation/createOrganization.ts | 37 ++++++++++++-------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/models/Organization.ts b/src/models/Organization.ts index 2ee482bea6..7a13d132d2 100644 --- a/src/models/Organization.ts +++ b/src/models/Organization.ts @@ -77,9 +77,11 @@ const organizationSchema = new Schema( address: { city: { type: String, + required: true, }, countryCode: { type: String, + required: true, }, dependentLocality: { type: String, diff --git a/src/resolvers/Mutation/createOrganization.ts b/src/resolvers/Mutation/createOrganization.ts index b0fcc926f2..ff44149475 100644 --- a/src/resolvers/Mutation/createOrganization.ts +++ b/src/resolvers/Mutation/createOrganization.ts @@ -53,6 +53,7 @@ export const createOrganization: MutationResolvers["createOrganization"] = if (args.data?.address) { validationResultAddress = validateAddress(args.data?.address); + console.log(validateAddress(args.data?.address)); } if (!validationResultName.isLessThanMaxLength) { @@ -130,32 +131,38 @@ function validateAddress(address: Address | undefined): { state, } = address; - const isCityValid = !!city && city.length > 0; - - // It should be a valid country code. + // Mandatory: It should be a valid country code. const isCountryCodeValid = !!countryCode && countryCode.length >= 2; - // It should exist and have a length greater than 0 + // 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 && dependentLocality.length > 0; + dependentLocality === undefined || + (typeof dependentLocality === "string" && dependentLocality.length >= 0); - // Line 1 should exist and have a length greater than 0 - const isLine1Valid = !!line1 && line1.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 + // Optional: Line 2 should exist and have a length greater than 0, if provided const isLine2Valid = - line2 === undefined || (typeof line2 === "string" && line2.length > 0); + line2 === undefined || (typeof line2 === "string" && line2.length >= 0); - // It should exist and have a valid format. - const isPostalCodeValid = !!postalCode && /^\d+$/.test(postalCode); + // Optional: It should exist and have a valid format. + const isPostalCodeValid = + postalCode === undefined || + (typeof postalCode === "string" && /^\d*$/.test(postalCode)); - //Optional + // Optional: It should exist and have a length greater than 0, if provided const isSortingCodeValid = sortingCode === undefined || - (typeof sortingCode === "string" && sortingCode.length > 0); + (typeof sortingCode === "string" && sortingCode.length >= 0); - // It should exist and have a length greater than 0 - const isStateValid = !!state && state.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 && From c1ec450f1baf3417a3827dae4bd00d1929b82370 Mon Sep 17 00:00:00 2001 From: Anubhav Banerjee Date: Fri, 26 Jan 2024 10:25:28 +0530 Subject: [PATCH 18/19] Fixed a bug in tests --- src/resolvers/Mutation/createOrganization.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/resolvers/Mutation/createOrganization.ts b/src/resolvers/Mutation/createOrganization.ts index ff44149475..f321982f14 100644 --- a/src/resolvers/Mutation/createOrganization.ts +++ b/src/resolvers/Mutation/createOrganization.ts @@ -53,7 +53,6 @@ export const createOrganization: MutationResolvers["createOrganization"] = if (args.data?.address) { validationResultAddress = validateAddress(args.data?.address); - console.log(validateAddress(args.data?.address)); } if (!validationResultName.isLessThanMaxLength) { From 1080e53a91d373d7ddbdc11b7fd829cb0e6284b4 Mon Sep 17 00:00:00 2001 From: Anubhav Banerjee Date: Sat, 27 Jan 2024 11:26:11 +0530 Subject: [PATCH 19/19] Fixed test cases --- src/models/Organization.ts | 2 -- .../Mutation/removeOrganization.spec.ts | 20 ++++++++++++++++++- .../Mutation/removeOrganizationImage.spec.ts | 11 +++++++++- .../Mutation/removeSampleOrganization.spec.ts | 5 +---- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/models/Organization.ts b/src/models/Organization.ts index 7a13d132d2..2ee482bea6 100644 --- a/src/models/Organization.ts +++ b/src/models/Organization.ts @@ -77,11 +77,9 @@ const organizationSchema = new Schema( address: { city: { type: String, - required: true, }, countryCode: { type: String, - required: true, }, dependentLocality: { type: String, 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",