Skip to content

Commit

Permalink
chore(package): Fixed tests and did housekeeping (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdip-b authored Nov 18, 2024
1 parent 210c0fd commit 40008e3
Show file tree
Hide file tree
Showing 21 changed files with 53 additions and 89 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"build:web": "turbo run build --filter=web",
"build:platform": "turbo run build --filter=platform",
"build:cli": "pnpm build:secret-scan && pnpm build:api-client && turbo run build --filter=cli",
"build:api-client": "turbo run --filter=api-client build",
"build:api-client": "pnpm build:schema && turbo run --filter=api-client build",
"build:schema": "turbo run build --filter=schema",
"build:secret-scan": "turbo run build --filter=secret-scan",
"start": "turbo run start",
Expand Down Expand Up @@ -163,6 +163,7 @@
},
"dependencies": {
"@keyshade/api-client": "workspace:*",
"@keyshade/schema": "workspace:*",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^12.0.0",
"@semantic-release/git": "^10.0.1",
Expand Down
3 changes: 0 additions & 3 deletions packages/api-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@
"test": "cross-env BACKEND_URL=http://localhost:4200 jest --runInBand",
"lint": "eslint \"{src,tests}/**/*.ts\" --fix",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\""
},
"dependencies": {
"@keyshade/schema": "workspace:*"
}
}
6 changes: 3 additions & 3 deletions packages/api-client/src/controllers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ export default class UserController {
request: UpdateSelfRequest,
headers?: Record<string, string>
): Promise<ClientResponse<UpdateSelfResponse>> {
const response = await this.apiClient.put(`./api/user`, request, headers)
const response = await this.apiClient.put(`/api/user`, request, headers)
return await parseResponse<UpdateSelfResponse>(response)
}

async deleteSelf(
headers?: Record<string, string>
): Promise<ClientResponse<DeleteSelfResponse>> {
const response = await this.apiClient.delete(`./api/user`, headers)
const response = await this.apiClient.delete(`/api/user`, headers)
return await parseResponse<DeleteSelfResponse>(response)
}

Expand All @@ -57,7 +57,7 @@ export default class UserController {
headers?: Record<string, string>
): Promise<ClientResponse<ResendEmailChangeOTPResponse>> {
const response = await this.apiClient.post(
`./api/user/resend-email-change-otp`,
`/api/user/resend-email-change-otp`,
request,
headers
)
Expand Down
17 changes: 1 addition & 16 deletions packages/api-client/tests/user.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,16 @@ describe('User Controller Tests', () => {
it('should get current user', async () => {
const user = await userController.getSelf({ 'x-e2e-user-email': email })

expect(user.data.defaultWorkspace.name).toBe('My Workspace')
expect(user.data.email).toBe('[email protected]')
})

// Update Current User
it('should update current user', async () => {
const user = await userController.updateSelf(
{ name: 'Jane Doe', email: '[email protected]' },
{ name: 'Jane Doe' },
{ 'x-e2e-user-email': email }
)

expect(user.data.name).toBe('Jane Doe')
expect(user.data.email).toBe('[email protected]')
})

// Delete Current User
it('should update current user', async () => {
const deleteUser = await userController.updateSelf(
{ name: 'Jane Doe', email: '[email protected]' },
{ 'x-e2e-user-email': email }
)

expect(deleteUser.success).toBe(true)
})

// Validate email change OTP
// resend validate email OTP tests
})
4 changes: 2 additions & 2 deletions packages/api-client/tests/workspace-membership.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Workspace Membership Controller Tests', () => {
const workspaceMembershipController = new WorkspaceMembershipController(
backendUrl
)
const userEmail = 'testuser@example.com'
const userEmail = 'johndoe@example.com'
let workspaceSlug: string | null

beforeAll(async () => {
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('Workspace Membership Controller Tests', () => {
'x-e2e-user-email': userEmail
})

expect(response).toBe(true)
expect(response.data).toBe(true)
})

it('should get a list of members', async () => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from 'zod'
import { ResendOTPRequestSchema, ResendOTPResponseSchema } from './auth'
import { ResendOTPRequestSchema, ResendOTPResponseSchema } from '.'

export type ResendOTPRequest = z.infer<typeof ResendOTPRequestSchema>

Expand Down
2 changes: 1 addition & 1 deletion packages/schema/src/environment/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from 'zod'
import { PageRequestSchema, PageResponseSchema } from '@/pagination/pagination'
import { PageRequestSchema, PageResponseSchema } from '@/pagination'

export const EnvironmentSchema = z.object({
id: z.string(),
Expand Down
11 changes: 3 additions & 8 deletions packages/schema/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
//Export all Schemas and types

export * from './pagination/pagination'

export * from './pagination'
export * from './api-key'

export * from './auth/auth'

export * from './auth'
export * from './enums'
export * from './environment'
export * from './integration'
export * from './project'
export * from './secret'
export * from './user'
export * from './variable'

export * from './workspace/workspace'

export * from './workspace'
export * from './workspace-role'
23 changes: 7 additions & 16 deletions packages/schema/src/index.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,22 @@ import {
UpdateWorkspaceRoleSchema
} from './workspace-role'

//Export types from pagination.types.ts
export * from './pagination/pagination.types'
export * from './pagination/index.types'
export * from './auth/index.types'
export * from './environment/index.types'
export * from './project/index.types'
export * from './secret/index.types'
export * from './user/index.types'
export * from './workspace/index.types'

export type TCreateApiKey = z.infer<typeof CreateApiKeySchema>
export type TUpdateApiKey = z.infer<typeof UpdateApiKeySchema>

// Export types from auth.types.ts
export * from './auth/auth.types'

export * from './environment/index.types'

export type TCreateIntegration = z.infer<typeof CreateIntegrationSchema>
export type TUpdateIntegration = z.infer<typeof UpdateIntegrationSchema>

export * from './project/index.types'

export * from './secret/index.types'

export * from './user/index.types'

export type TCreateVariable = z.infer<typeof CreateVariableSchema>
export type TUpdateVariable = z.infer<typeof UpdateVariableSchema>

// Export types from workspace.types.ts
export * from './workspace/workspace.types'

export type TCreateWorkspaceRole = z.infer<typeof CreateWorkspaceRoleSchema>
export type TUpdateWorkspaceRole = z.infer<typeof UpdateWorkspaceRoleSchema>
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
PageRequestSchema,
PageResponseSchema,
ResponseErrorSchema
} from './pagination'
} from '.'

export type PageRequest = z.infer<typeof PageRequestSchema>

Expand Down
2 changes: 1 addition & 1 deletion packages/schema/src/project/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from 'zod'
import { PageRequestSchema, PageResponseSchema } from '@/pagination/pagination'
import { PageRequestSchema, PageResponseSchema } from '@/pagination'
import { CreateEnvironmentRequestSchema } from '@/environment'
import { projectAccessLevelEnum } from '@/enums'

Expand Down
2 changes: 1 addition & 1 deletion packages/schema/src/secret/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from 'zod'
import { PageRequestSchema, PageResponseSchema } from '@/pagination/pagination'
import { PageRequestSchema, PageResponseSchema } from '@/pagination'
import { rotateAfterEnum } from '@/enums'

export const SecretSchema = z.object({
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/src/user/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from 'zod'
import { WorkspaceSchema } from '@/workspace/workspace'
import { WorkspaceSchema } from '@/workspace'

export const GetSelfResponseSchema = z.object({
id: z.string(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { z } from 'zod'
import { PageRequestSchema, PageResponseSchema } from '@/pagination/pagination'
import { PageRequestSchema, PageResponseSchema } from '@/pagination'
import { projectAccessLevelEnum, rotateAfterEnum } from '@/enums'

export const InviteMemberSchema = z.object({
email: z.string().email(),
roleSlugs: z.array(z.string()).optional()
})

//Request and Response types
export const WorkspaceSchema = z.object({
id: z.string(),
name: z.string(),
Expand Down Expand Up @@ -46,6 +40,11 @@ export const GetWorkspaceRequestSchema = z.object({
workspaceSlug: z.string()
})

export const InviteMemberSchema = z.object({
email: z.string().email(),
roleSlugs: z.array(z.string()).optional()
})

export const GetWorkspaceResponseSchema = WorkspaceSchema

export const GetAllWorkspacesOfUserRequestSchema = PageRequestSchema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
ExportDataResponseSchema,
GlobalSearchRequestSchema,
GlobalSearchResponseSchema
} from './workspace'
} from '.'
import { PageRequestSchema } from '..'

export type Workspace = z.infer<typeof WorkspaceSchema>
Expand Down
5 changes: 1 addition & 4 deletions packages/schema/tests/auth.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
ResendOTPRequestSchema,
ResendOTPResponseSchema
} from '../src/auth/auth'
import { ResendOTPRequestSchema, ResendOTPResponseSchema } from '../src/auth'

describe('Auth Schema Tests', () => {
// Tests for ResendOTPRequestSchema
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/tests/pagination.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
PageResponseSchema,
ResponseErrorSchema,
ClientResponseSchema
} from '@/pagination/pagination'
} from '@/pagination'

describe('Pagination Schema Tests', () => {
// Tests for PageRequestSchema
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/tests/workspace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
GetAllWorkspacesOfUserResponseSchema,
GlobalSearchResponseSchema,
GetAllWorkspacesOfUserRequestSchema
} from '@/workspace/workspace'
} from '@/workspace'

describe('Workspace Schema Tests', () => {
it('should validate if proper input is specified for InviteMemberSchema', () => {
Expand Down
Loading

0 comments on commit 40008e3

Please sign in to comment.