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', () => {
|
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(
|
const result = await teamCollectionService.createCollection(
|
||||||
rootTeamCollection.teamID,
|
rootTeamCollection.teamID,
|
||||||
'ab',
|
'',
|
||||||
JSON.stringify(rootTeamCollection.data),
|
JSON.stringify(rootTeamCollection.data),
|
||||||
rootTeamCollection.id,
|
rootTeamCollection.id,
|
||||||
);
|
);
|
||||||
|
|
@ -781,10 +781,10 @@ describe('createCollection', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('renameCollection', () => {
|
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(
|
const result = await teamCollectionService.renameCollection(
|
||||||
rootTeamCollection.id,
|
rootTeamCollection.id,
|
||||||
'ab',
|
'',
|
||||||
);
|
);
|
||||||
expect(result).toEqualLeft(TEAM_COLL_SHORT_TITLE);
|
expect(result).toEqualLeft(TEAM_COLL_SHORT_TITLE);
|
||||||
});
|
});
|
||||||
|
|
@ -1464,7 +1464,7 @@ describe('updateTeamCollection', () => {
|
||||||
const result = await teamCollectionService.updateTeamCollection(
|
const result = await teamCollectionService.updateTeamCollection(
|
||||||
rootTeamCollection.id,
|
rootTeamCollection.id,
|
||||||
JSON.stringify(rootTeamCollection.data),
|
JSON.stringify(rootTeamCollection.data),
|
||||||
'de',
|
'',
|
||||||
);
|
);
|
||||||
expect(result).toEqualLeft(TEAM_COLL_SHORT_TITLE);
|
expect(result).toEqualLeft(TEAM_COLL_SHORT_TITLE);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ export class TeamCollectionService {
|
||||||
private readonly teamService: TeamService,
|
private readonly teamService: TeamService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
TITLE_LENGTH = 3;
|
TITLE_LENGTH = 1;
|
||||||
MAX_RETRIES = 5; // Maximum number of retries for database transactions
|
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 () => {
|
test('should throw TEAM_ENVIRONMENT_SHORT_NAME if input TeamEnvironment name is invalid', async () => {
|
||||||
const result = await teamEnvironmentsService.createTeamEnvironment(
|
const result = await teamEnvironmentsService.createTeamEnvironment(
|
||||||
'12',
|
'',
|
||||||
teamEnvironment.teamID,
|
teamEnvironment.teamID,
|
||||||
JSON.stringify(teamEnvironment.variables),
|
JSON.stringify(teamEnvironment.variables),
|
||||||
);
|
);
|
||||||
|
|
@ -218,7 +218,7 @@ describe('TeamEnvironmentsService', () => {
|
||||||
test('should throw TEAM_ENVIRONMENT_SHORT_NAME if input TeamEnvironment name is invalid', async () => {
|
test('should throw TEAM_ENVIRONMENT_SHORT_NAME if input TeamEnvironment name is invalid', async () => {
|
||||||
const result = await teamEnvironmentsService.updateTeamEnvironment(
|
const result = await teamEnvironmentsService.updateTeamEnvironment(
|
||||||
teamEnvironment.id,
|
teamEnvironment.id,
|
||||||
'12',
|
'',
|
||||||
JSON.stringify([{ key: 'value' }]),
|
JSON.stringify([{ key: 'value' }]),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ export class TeamEnvironmentsService {
|
||||||
private readonly teamService: TeamService,
|
private readonly teamService: TeamService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
TITLE_LENGTH = 3;
|
TITLE_LENGTH = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TeamEnvironments are saved in the DB in the following way
|
* 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 E from 'fp-ts/Either';
|
||||||
import * as T from 'fp-ts/Task';
|
import * as T from 'fp-ts/Task';
|
||||||
import * as A from 'fp-ts/Array';
|
import * as A from 'fp-ts/Array';
|
||||||
import { throwErr } from 'src/utils';
|
import { isValidLength, throwErr } from 'src/utils';
|
||||||
import { AuthUser } from '../types/AuthUser';
|
import { AuthUser } from '../types/AuthUser';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|
@ -32,6 +32,8 @@ export class TeamService implements UserDataHandler, OnModuleInit {
|
||||||
private readonly pubsub: PubSubService,
|
private readonly pubsub: PubSubService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
TITLE_LENGTH = 1;
|
||||||
|
|
||||||
onModuleInit() {
|
onModuleInit() {
|
||||||
this.userService.registerUserDataHandler(this);
|
this.userService.registerUserDataHandler(this);
|
||||||
}
|
}
|
||||||
|
|
@ -123,17 +125,12 @@ export class TeamService implements UserDataHandler, OnModuleInit {
|
||||||
return E.right(true);
|
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(
|
async renameTeam(
|
||||||
teamID: string,
|
teamID: string,
|
||||||
newName: string,
|
newName: string,
|
||||||
): Promise<E.Left<string> | E.Right<Team>> {
|
): Promise<E.Left<string> | E.Right<Team>> {
|
||||||
const isValidTitle = this.validateTeamName(newName);
|
const isValidTitle = isValidLength(newName, this.TITLE_LENGTH);
|
||||||
if (E.isLeft(isValidTitle)) return isValidTitle;
|
if (!isValidTitle) return E.left(TEAM_NAME_INVALID);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const updatedTeam = await this.prisma.team.update({
|
const updatedTeam = await this.prisma.team.update({
|
||||||
|
|
@ -245,8 +242,8 @@ export class TeamService implements UserDataHandler, OnModuleInit {
|
||||||
name: string,
|
name: string,
|
||||||
creatorUid: string,
|
creatorUid: string,
|
||||||
): Promise<E.Left<string> | E.Right<Team>> {
|
): Promise<E.Left<string> | E.Right<Team>> {
|
||||||
const isValidName = this.validateTeamName(name);
|
const isValidName = isValidLength(name, this.TITLE_LENGTH);
|
||||||
if (E.isLeft(isValidName)) return isValidName;
|
if (!isValidName) return E.left(TEAM_NAME_INVALID);
|
||||||
|
|
||||||
const team = await this.prisma.team.create({
|
const team = await this.prisma.team.create({
|
||||||
data: {
|
data: {
|
||||||
|
|
|
||||||
|
|
@ -229,7 +229,7 @@ export function stringToJson<T>(
|
||||||
* @returns boolean if title is of valid length or not
|
* @returns boolean if title is of valid length or not
|
||||||
*/
|
*/
|
||||||
export function isValidLength(title: string, length: number) {
|
export function isValidLength(title: string, length: number) {
|
||||||
if (title.length < length) {
|
if (!title || title.trim() === '' || title.length < length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -477,7 +477,7 @@
|
||||||
"select": "Select environment",
|
"select": "Select environment",
|
||||||
"set": "Set environment",
|
"set": "Set environment",
|
||||||
"set_as_environment": "Set as 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",
|
"team_environments": "Workspace Environments",
|
||||||
"title": "Environments",
|
"title": "Environments",
|
||||||
"updated": "Environment updated",
|
"updated": "Environment updated",
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,8 @@ const t = useI18n()
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
show: boolean
|
show?: boolean
|
||||||
loadingState: boolean
|
loadingState?: boolean
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
show: false,
|
show: false,
|
||||||
|
|
@ -73,7 +73,7 @@ const addNewCollection = () => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!editingName.value) {
|
if (editingName.value.trim() === "") {
|
||||||
toast.error(t("collection.invalid_name"))
|
toast.error(t("collection.invalid_name"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,8 @@ const t = useI18n()
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
show: boolean
|
show?: boolean
|
||||||
loadingState: boolean
|
loadingState?: boolean
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
show: false,
|
show: false,
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,8 @@ const t = useI18n()
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
show: boolean
|
show?: boolean
|
||||||
loadingState: boolean
|
loadingState?: boolean
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
show: false,
|
show: false,
|
||||||
|
|
|
||||||
|
|
@ -512,7 +512,7 @@ const saveEnvironment = () => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editingName.value.length < 3) {
|
if (editingName.value.trim().length === 0) {
|
||||||
toast.error(`${t("environment.short_name")}`)
|
toast.error(`${t("environment.short_name")}`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -496,6 +496,12 @@ const saveEnvironment = async () => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (editingName.value.trim().length === 0) {
|
||||||
|
isLoading.value = false
|
||||||
|
toast.error(`${t("environment.short_name")}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const filteredVariables = pipe(
|
const filteredVariables = pipe(
|
||||||
vars.value,
|
vars.value,
|
||||||
A.filterMap(
|
A.filterMap(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue