Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

chore: accept single character length name and trim white spaces (#5412)

Nivedin35e01e128099
diff --git a/packages/hoppscotch-backend/src/team-collection/team-collection.service.spec.ts b/packages/hoppscotch-backend/src/team-collection/team-collection.service.spec.ts
index 6a91c80a7..cc1dbc871 100644
--- a/packages/hoppscotch-backend/src/team-collection/team-collection.service.spec.ts
+++ b/packages/hoppscotch-backend/src/team-collection/team-collection.service.spec.ts
@@ -661,10 +661,10 @@ describe('getCollection', () => {
});
describe('createCollection', () => {
- test('should throw TEAM_COLL_SHORT_TITLE when title is less than 3 characters', async () => {
+ test('should throw TEAM_COLL_SHORT_TITLE when title is less than 1 character', async () => {
const result = await teamCollectionService.createCollection(
rootTeamCollection.teamID,
- 'ab',
+ '',
JSON.stringify(rootTeamCollection.data),
rootTeamCollection.id,
);
@@ -781,10 +781,10 @@ describe('createCollection', () => {
});
describe('renameCollection', () => {
- test('should throw TEAM_COLL_SHORT_TITLE when title is less than 3 characters', async () => {
+ test('should throw TEAM_COLL_SHORT_TITLE when title is less than 1 character', async () => {
const result = await teamCollectionService.renameCollection(
rootTeamCollection.id,
- 'ab',
+ '',
);
expect(result).toEqualLeft(TEAM_COLL_SHORT_TITLE);
});
@@ -1464,7 +1464,7 @@ describe('updateTeamCollection', () => {
const result = await teamCollectionService.updateTeamCollection(
rootTeamCollection.id,
JSON.stringify(rootTeamCollection.data),
- 'de',
+ '',
);
expect(result).toEqualLeft(TEAM_COLL_SHORT_TITLE);
});
diff --git a/packages/hoppscotch-backend/src/team-collection/team-collection.service.ts b/packages/hoppscotch-backend/src/team-collection/team-collection.service.ts
index bb1eabbf0..ac6f9147a 100644
--- a/packages/hoppscotch-backend/src/team-collection/team-collection.service.ts
+++ b/packages/hoppscotch-backend/src/team-collection/team-collection.service.ts
@@ -56,7 +56,7 @@ export class TeamCollectionService {
private readonly teamService: TeamService,
) {}
- TITLE_LENGTH = 3;
+ TITLE_LENGTH = 1;
MAX_RETRIES = 5; // Maximum number of retries for database transactions
/**
diff --git a/packages/hoppscotch-backend/src/team-environments/team-environments.service.spec.ts b/packages/hoppscotch-backend/src/team-environments/team-environments.service.spec.ts
index cda17f4b3..318b8f5d6 100644
--- a/packages/hoppscotch-backend/src/team-environments/team-environments.service.spec.ts
+++ b/packages/hoppscotch-backend/src/team-environments/team-environments.service.spec.ts
@@ -80,7 +80,7 @@ describe('TeamEnvironmentsService', () => {
test('should throw TEAM_ENVIRONMENT_SHORT_NAME if input TeamEnvironment name is invalid', async () => {
const result = await teamEnvironmentsService.createTeamEnvironment(
- '12',
+ '',
teamEnvironment.teamID,
JSON.stringify(teamEnvironment.variables),
);
@@ -218,7 +218,7 @@ describe('TeamEnvironmentsService', () => {
test('should throw TEAM_ENVIRONMENT_SHORT_NAME if input TeamEnvironment name is invalid', async () => {
const result = await teamEnvironmentsService.updateTeamEnvironment(
teamEnvironment.id,
- '12',
+ '',
JSON.stringify([{ key: 'value' }]),
);
diff --git a/packages/hoppscotch-backend/src/team-environments/team-environments.service.ts b/packages/hoppscotch-backend/src/team-environments/team-environments.service.ts
index a7888b3d8..bb85f7b6b 100644
--- a/packages/hoppscotch-backend/src/team-environments/team-environments.service.ts
+++ b/packages/hoppscotch-backend/src/team-environments/team-environments.service.ts
@@ -19,7 +19,7 @@ export class TeamEnvironmentsService {
private readonly teamService: TeamService,
) {}
- TITLE_LENGTH = 3;
+ TITLE_LENGTH = 1;
/**
* TeamEnvironments are saved in the DB in the following way
diff --git a/packages/hoppscotch-backend/src/team/team.service.ts b/packages/hoppscotch-backend/src/team/team.service.ts
index 11ea9613f..1c08b8a05 100644
--- a/packages/hoppscotch-backend/src/team/team.service.ts
+++ b/packages/hoppscotch-backend/src/team/team.service.ts
@@ -21,7 +21,7 @@ import * as O from 'fp-ts/Option';
import * as E from 'fp-ts/Either';
import * as T from 'fp-ts/Task';
import * as A from 'fp-ts/Array';
-import { throwErr } from 'src/utils';
+import { isValidLength, throwErr } from 'src/utils';
import { AuthUser } from '../types/AuthUser';
@Injectable()
@@ -32,6 +32,8 @@ export class TeamService implements UserDataHandler, OnModuleInit {
private readonly pubsub: PubSubService,
) {}
+ TITLE_LENGTH = 1;
+
onModuleInit() {
this.userService.registerUserDataHandler(this);
}
@@ -123,17 +125,12 @@ export class TeamService implements UserDataHandler, OnModuleInit {
return E.right(true);
}
- validateTeamName(title: string): E.Left<string> | E.Right<boolean> {
- if (!title || title.trim() === '') return E.left(TEAM_NAME_INVALID);
- return E.right(true);
- }
-
async renameTeam(
teamID: string,
newName: string,
): Promise<E.Left<string> | E.Right<Team>> {
- const isValidTitle = this.validateTeamName(newName);
- if (E.isLeft(isValidTitle)) return isValidTitle;
+ const isValidTitle = isValidLength(newName, this.TITLE_LENGTH);
+ if (!isValidTitle) return E.left(TEAM_NAME_INVALID);
try {
const updatedTeam = await this.prisma.team.update({
@@ -245,8 +242,8 @@ export class TeamService implements UserDataHandler, OnModuleInit {
name: string,
creatorUid: string,
): Promise<E.Left<string> | E.Right<Team>> {
- const isValidName = this.validateTeamName(name);
- if (E.isLeft(isValidName)) return isValidName;
+ const isValidName = isValidLength(name, this.TITLE_LENGTH);
+ if (!isValidName) return E.left(TEAM_NAME_INVALID);
const team = await this.prisma.team.create({
data: {
diff --git a/packages/hoppscotch-backend/src/utils.ts b/packages/hoppscotch-backend/src/utils.ts
index a8e618f2a..4ac5423f5 100644
--- a/packages/hoppscotch-backend/src/utils.ts
+++ b/packages/hoppscotch-backend/src/utils.ts
@@ -229,7 +229,7 @@ export function stringToJson<T>(
* @returns boolean if title is of valid length or not
*/
export function isValidLength(title: string, length: number) {
- if (title.length < length) {
+ if (!title || title.trim() === '' || title.length < length) {
return false;
}
diff --git a/packages/hoppscotch-common/locales/en.json b/packages/hoppscotch-common/locales/en.json
index 07b36df87..a2e2323b6 100644
--- a/packages/hoppscotch-common/locales/en.json
+++ b/packages/hoppscotch-common/locales/en.json
@@ -477,7 +477,7 @@
"select": "Select environment",
"set": "Set environment",
"set_as_environment": "Set as environment",
- "short_name": "Environment needs to have minimum 3 characters",
+ "short_name": "Environment needs to have minimum 1 character in its name",
"team_environments": "Workspace Environments",
"title": "Environments",
"updated": "Environment updated",
diff --git a/packages/hoppscotch-common/src/components/collections/Add.vue b/packages/hoppscotch-common/src/components/collections/Add.vue
index 4d2a81d42..e2708fffa 100644
--- a/packages/hoppscotch-common/src/components/collections/Add.vue
+++ b/packages/hoppscotch-common/src/components/collections/Add.vue
@@ -43,8 +43,8 @@ const t = useI18n()
const props = withDefaults(
defineProps<{
- show: boolean
- loadingState: boolean
+ show?: boolean
+ loadingState?: boolean
}>(),
{
show: false,
@@ -73,7 +73,7 @@ const addNewCollection = () => {
return
}
- if (!editingName.value) {
+ if (editingName.value.trim() === "") {
toast.error(t("collection.invalid_name"))
return
}
diff --git a/packages/hoppscotch-common/src/components/collections/AddFolder.vue b/packages/hoppscotch-common/src/components/collections/AddFolder.vue
index 30cec3b09..faad5dad8 100644
--- a/packages/hoppscotch-common/src/components/collections/AddFolder.vue
+++ b/packages/hoppscotch-common/src/components/collections/AddFolder.vue
@@ -43,8 +43,8 @@ const t = useI18n()
const props = withDefaults(
defineProps<{
- show: boolean
- loadingState: boolean
+ show?: boolean
+ loadingState?: boolean
}>(),
{
show: false,
diff --git a/packages/hoppscotch-common/src/components/collections/AddRequest.vue b/packages/hoppscotch-common/src/components/collections/AddRequest.vue
index 358ff062d..381e76968 100644
--- a/packages/hoppscotch-common/src/components/collections/AddRequest.vue
+++ b/packages/hoppscotch-common/src/components/collections/AddRequest.vue
@@ -48,8 +48,8 @@ const t = useI18n()
const props = withDefaults(
defineProps<{
- show: boolean
- loadingState: boolean
+ show?: boolean
+ loadingState?: boolean
}>(),
{
show: false,
diff --git a/packages/hoppscotch-common/src/components/environments/my/Details.vue b/packages/hoppscotch-common/src/components/environments/my/Details.vue
index ba773fec9..6ceb12bd1 100644
--- a/packages/hoppscotch-common/src/components/environments/my/Details.vue
+++ b/packages/hoppscotch-common/src/components/environments/my/Details.vue
@@ -512,7 +512,7 @@ const saveEnvironment = () => {
return
}
- if (editingName.value.length < 3) {
+ if (editingName.value.trim().length === 0) {
toast.error(`${t("environment.short_name")}`)
return
}
diff --git a/packages/hoppscotch-common/src/components/environments/teams/Details.vue b/packages/hoppscotch-common/src/components/environments/teams/Details.vue
index d8f3a5cc1..ba40ed11a 100644
--- a/packages/hoppscotch-common/src/components/environments/teams/Details.vue
+++ b/packages/hoppscotch-common/src/components/environments/teams/Details.vue
@@ -496,6 +496,12 @@ const saveEnvironment = async () => {
return
}
+ if (editingName.value.trim().length === 0) {
+ isLoading.value = false
+ toast.error(`${t("environment.short_name")}`)
+ return
+ }
+
const filteredVariables = pipe(
vars.value,
A.filterMap(