generated from RealDevSquad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 280
test: add test for the application create flow #2536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
iamitprakash
merged 8 commits into
RealDevSquad:develop
from
AnujChhikara:anuj/create-application-test
Jan 14, 2026
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ac006be
refactor: restructure application constants and enhance application c…
AnujChhikara 1c501e6
test: add imageUrl to application data in integration and validation …
AnujChhikara 6e96612
refactor: enhance application constants and update application retrie…
AnujChhikara b77fc04
feat: add new API response message for successful application retrieval
AnujChhikara 96d8594
test: add unit tests for createApplicationService to validate applica…
AnujChhikara 54bcc98
refactor: simplify imageUrl assignment in application transformation …
AnujChhikara a1623ca
test: update createApplicationService test to focus on socialLink han…
AnujChhikara 0e9af59
Merge branch 'develop' into anuj/create-application-test
AnujChhikara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,38 @@ | ||
| const APPLICATION_STATUS_TYPES = ["accepted", "rejected", "pending"]; | ||
| const APPLICATION_STATUS_TYPES = { | ||
| ACCEPTED: "accepted", | ||
| REJECTED: "rejected", | ||
| PENDING: "pending", | ||
| CHANGES_REQUESTED: "changes_requested", | ||
| }; | ||
|
|
||
| const APPLICATION_ROLES = { | ||
| DEVELOPER: "developer", | ||
| DESIGNER: "designer", | ||
| PRODUCT_MANAGER: "product_manager", | ||
| PROJECT_MANAGER: "project_manager", | ||
| QA: "qa", | ||
| SOCIAL_MEDIA: "social_media", | ||
| }; | ||
|
|
||
| const API_RESPONSE_MESSAGES = { | ||
| APPLICATION_CREATED_SUCCESS: "Application created successfully", | ||
| APPLICATION_RETURN_SUCCESS: "Applications returned successfully", | ||
| }; | ||
|
|
||
| module.exports = { APPLICATION_STATUS_TYPES, API_RESPONSE_MESSAGES }; | ||
| const APPLICATION_ERROR_MESSAGES = { | ||
| APPLICATION_ALREADY_REVIEWED: "Application has already been reviewed", | ||
| }; | ||
|
|
||
| /** | ||
| * Business requirement: Applications created after this date are considered reviewed | ||
| * and cannot be resubmitted. This date marks the start of the new application review cycle. | ||
| */ | ||
| const APPLICATION_REVIEW_CYCLE_START_DATE = new Date("2026-01-01T00:00:00.000Z"); | ||
|
|
||
| module.exports = { | ||
| APPLICATION_STATUS_TYPES, | ||
| APPLICATION_ROLES, | ||
| API_RESPONSE_MESSAGES, | ||
| APPLICATION_ERROR_MESSAGES, | ||
| APPLICATION_REVIEW_CYCLE_START_DATE, | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,111 @@ | ||
| import { application, applicationPayload } from "../types/application"; | ||
| import { Conflict } from "http-errors"; | ||
| const ApplicationModel = require("../models/applications"); | ||
| const { | ||
| APPLICATION_STATUS_TYPES, | ||
| APPLICATION_ERROR_MESSAGES, | ||
| APPLICATION_REVIEW_CYCLE_START_DATE, | ||
| } = require("../constants/application"); | ||
| const logger = require("../utils/logger"); | ||
|
|
||
| interface CreateApplicationServiceParams { | ||
| userId: string; | ||
| payload: applicationPayload; | ||
| } | ||
|
|
||
| interface CreateApplicationServiceResponse { | ||
| applicationId: string; | ||
| isNew: boolean; | ||
| } | ||
|
|
||
| const transformPayloadToApplication = (payload: applicationPayload, userId: string): application => { | ||
| const transformed: application = { | ||
| userId, | ||
| biodata: { | ||
| firstName: payload.firstName, | ||
| lastName: payload.lastName, | ||
| }, | ||
| location: { | ||
| city: payload.city, | ||
| state: payload.state, | ||
| country: payload.country, | ||
| }, | ||
| professional: { | ||
| institution: payload.college, | ||
| skills: payload.skills, | ||
| }, | ||
| intro: { | ||
| introduction: payload.introduction, | ||
| funFact: payload.funFact, | ||
| forFun: payload.forFun, | ||
| whyRds: payload.whyRds, | ||
| numberOfHours: payload.numberOfHours, | ||
| }, | ||
| foundFrom: payload.foundFrom, | ||
| role: payload.role, | ||
| }; | ||
|
|
||
| if (payload.imageUrl) { | ||
| transformed.imageUrl = payload.imageUrl; | ||
| } | ||
|
|
||
| if (payload.socialLink) { | ||
| transformed.socialLink = payload.socialLink; | ||
| } | ||
|
|
||
| return transformed; | ||
| }; | ||
|
|
||
| /** | ||
| * Service to create application | ||
| * Handles the logic for: | ||
| * - Checking existing applications created after the review cycle start date (business requirement) | ||
| * - Creating new applications if no application found after the review cycle start date | ||
| * - Always creates a new application (no update flow) | ||
| * | ||
| * @param params - Object containing userId and payload | ||
| * @returns Promise resolving to application creation response | ||
| * @throws Conflict if application already exists after the review cycle start date | ||
| */ | ||
| export const createApplicationService = async ( | ||
| params: CreateApplicationServiceParams | ||
| ): Promise<CreateApplicationServiceResponse> => { | ||
| try { | ||
| const { userId, payload } = params; | ||
|
|
||
| const userApplications = await ApplicationModel.getUserApplications(userId); | ||
| const existingApplication = userApplications.length > 0 ? userApplications[0] : null; | ||
|
|
||
| if (existingApplication) { | ||
| const existingCreatedAt = new Date(existingApplication.createdAt); | ||
|
|
||
| if (existingCreatedAt > APPLICATION_REVIEW_CYCLE_START_DATE) { | ||
| throw new Conflict(APPLICATION_ERROR_MESSAGES.APPLICATION_ALREADY_REVIEWED); | ||
| } | ||
| } | ||
AnujChhikara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const createdAt = new Date().toISOString(); | ||
|
|
||
| const applicationData: application = { | ||
| ...transformPayloadToApplication(payload, userId), | ||
| score: 0, | ||
| status: APPLICATION_STATUS_TYPES.PENDING, | ||
| createdAt, | ||
| isNew: true, | ||
| nudgeCount: 0, | ||
| }; | ||
|
|
||
| const applicationId = await ApplicationModel.addApplication(applicationData); | ||
|
|
||
| return { | ||
| applicationId, | ||
| isNew: true, | ||
| }; | ||
| } catch (err) { | ||
| if (err instanceof Conflict) { | ||
| throw err; | ||
| } | ||
| logger.error("Error in createApplicationService", err); | ||
| throw err; | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.