chore: accept single character length name and trim white spaces (#5412)
Co-authored-by: mirarifhasan <arif.ishan05@gmail.com>
This commit is contained in:
parent
2498ee7b08
commit
35e01e1280
12 changed files with 32 additions and 29 deletions
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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' }]),
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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: {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ const t = useI18n()
|
|||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
show: boolean
|
||||
loadingState: boolean
|
||||
show?: boolean
|
||||
loadingState?: boolean
|
||||
}>(),
|
||||
{
|
||||
show: false,
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@ const t = useI18n()
|
|||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
show: boolean
|
||||
loadingState: boolean
|
||||
show?: boolean
|
||||
loadingState?: boolean
|
||||
}>(),
|
||||
{
|
||||
show: false,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue