@nosto/nosto-cli 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/release.yml +3 -2
- package/package.json +5 -1
- package/test/api/deployments/createDeployment.test.ts +42 -0
- package/test/api/deployments/listDeployments.test.ts +88 -0
- package/test/api/deployments/rollbackDeployment.test.ts +30 -0
- package/test/api/deployments/updateDeployment.test.ts +32 -0
- package/test/commander.test.ts +155 -0
- package/test/modules/deployments/deploy.test.ts +200 -0
- package/test/modules/deployments/list.test.ts +101 -0
- package/test/modules/deployments/redeploy.test.ts +218 -0
- package/test/modules/deployments/rollback.test.ts +60 -0
- package/test/modules/search-templates/build.legacy.test.ts +85 -2
- package/test/modules/search-templates/build.modern.test.ts +106 -0
- package/test/setup.ts +3 -1
- package/test/utils/formatDate.test.ts +54 -0
- package/test/utils/mockConsole.ts +11 -0
- package/test/utils/mockDeployment.ts +44 -0
- package/test/utils/mockServer.ts +52 -0
- package/test/utils/validations.test.ts +58 -0
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { afterEach, expect, vi } from "vitest"
|
|
2
2
|
|
|
3
|
+
export const mockedInquirer = {
|
|
4
|
+
select: vi.fn()
|
|
5
|
+
}
|
|
6
|
+
|
|
3
7
|
export const mockedConsoleIn = {
|
|
4
8
|
userResponse: "q",
|
|
5
9
|
recordedPrompts: [] as string[],
|
|
@@ -47,6 +51,7 @@ export const mockedSpinner = {
|
|
|
47
51
|
export function setupMockConsole() {
|
|
48
52
|
afterEach(() => {
|
|
49
53
|
mockedConsoleIn.recordedPrompts = []
|
|
54
|
+
mockedInquirer.select.mockReset()
|
|
50
55
|
mockedSpinner.text = ""
|
|
51
56
|
vi.clearAllMocks()
|
|
52
57
|
})
|
|
@@ -55,6 +60,9 @@ export function setupMockConsole() {
|
|
|
55
60
|
setUserResponse: (response: string) => {
|
|
56
61
|
mockedConsoleIn.userResponse = response
|
|
57
62
|
},
|
|
63
|
+
setSelectResponse: (response: string | undefined) => {
|
|
64
|
+
mockedInquirer.select.mockResolvedValue(response)
|
|
65
|
+
},
|
|
58
66
|
setContext: (context: Partial<typeof mockedConsoleOut.Logger.context>) => {
|
|
59
67
|
mockedConsoleOut.Logger.context = {
|
|
60
68
|
...mockedConsoleOut.Logger.context,
|
|
@@ -85,6 +93,9 @@ export function setupMockConsole() {
|
|
|
85
93
|
getSpy: (method: Exclude<keyof typeof mockedConsoleOut.Logger, "context">) => {
|
|
86
94
|
return mockedConsoleOut.Logger[method]
|
|
87
95
|
},
|
|
96
|
+
getSelectSpy: () => {
|
|
97
|
+
return mockedInquirer.select
|
|
98
|
+
},
|
|
88
99
|
getSpinnerSpy: (method: keyof typeof mockedSpinner) => {
|
|
89
100
|
return mockedSpinner[method]
|
|
90
101
|
},
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
type DeploymentData = {
|
|
2
|
+
id?: string
|
|
3
|
+
created?: number
|
|
4
|
+
active?: boolean
|
|
5
|
+
latest?: boolean
|
|
6
|
+
userId?: string
|
|
7
|
+
description?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type MockDeployment = {
|
|
11
|
+
id: string
|
|
12
|
+
created: number
|
|
13
|
+
active: boolean
|
|
14
|
+
latest: boolean
|
|
15
|
+
userId?: string
|
|
16
|
+
description?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let deploymentCounter = 1763737000
|
|
20
|
+
|
|
21
|
+
export function createMockDeployment(overrides: DeploymentData = {}): MockDeployment {
|
|
22
|
+
const id = overrides.id ?? String(deploymentCounter++)
|
|
23
|
+
const created = overrides.created ?? 1732200000000
|
|
24
|
+
const active = overrides.active ?? false
|
|
25
|
+
const latest = overrides.latest ?? false
|
|
26
|
+
|
|
27
|
+
const deployment: MockDeployment = {
|
|
28
|
+
id,
|
|
29
|
+
created,
|
|
30
|
+
active,
|
|
31
|
+
latest
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Only add optional fields if they are explicitly provided
|
|
35
|
+
if (overrides.userId !== undefined) {
|
|
36
|
+
deployment.userId = overrides.userId
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (overrides.description !== undefined) {
|
|
40
|
+
deployment.description = overrides.description
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return deployment
|
|
44
|
+
}
|
package/test/utils/mockServer.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { SetupServer, setupServer } from "msw/node"
|
|
2
2
|
import { afterAll, afterEach, beforeAll, beforeEach } from "vitest"
|
|
3
3
|
|
|
4
|
+
// Deployment API functions (imported for ReturnType type inference)
|
|
5
|
+
import { createDeployment } from "#api/deployments/createDeployment.ts"
|
|
6
|
+
import { listDeployments } from "#api/deployments/listDeployments.ts"
|
|
7
|
+
import { rollbackDeployment } from "#api/deployments/rollbackDeployment.ts"
|
|
8
|
+
import { updateDeployment } from "#api/deployments/updateDeployment.ts"
|
|
9
|
+
// Library and source API functions (imported for ReturnType type inference)
|
|
4
10
|
import { fetchLibraryFile } from "#api/library/fetchLibraryFile.ts"
|
|
5
11
|
import { fetchSourceFile } from "#api/source/fetchSourceFile.ts"
|
|
6
12
|
import { listSourceFiles } from "#api/source/listSourceFiles.ts"
|
|
@@ -74,3 +80,49 @@ export function mockFetchLibraryFile(
|
|
|
74
80
|
path: `https://library.nosto.com/${params.path}`
|
|
75
81
|
})
|
|
76
82
|
}
|
|
83
|
+
|
|
84
|
+
export function mockListDeployments(
|
|
85
|
+
server: SetupServer,
|
|
86
|
+
params: MockParams<Awaited<ReturnType<typeof listDeployments>>>
|
|
87
|
+
) {
|
|
88
|
+
return generateEndpointMock(server, {
|
|
89
|
+
...params,
|
|
90
|
+
method: "get",
|
|
91
|
+
path: getSourceUrl("deployments/{env}")
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function mockCreateDeployment(
|
|
96
|
+
server: SetupServer,
|
|
97
|
+
params: { path: string } & MockParams<Awaited<ReturnType<typeof createDeployment>>>
|
|
98
|
+
) {
|
|
99
|
+
const { path, ...mockParams } = params
|
|
100
|
+
return generateEndpointMock(server, {
|
|
101
|
+
method: "post",
|
|
102
|
+
path: getSourceUrl(`deployments/{env}/${path}`),
|
|
103
|
+
...mockParams
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function mockUpdateDeployment(
|
|
108
|
+
server: SetupServer,
|
|
109
|
+
params: { deploymentId: string } & MockParams<Awaited<ReturnType<typeof updateDeployment>>>
|
|
110
|
+
) {
|
|
111
|
+
const { deploymentId, ...mockParams } = params
|
|
112
|
+
return generateEndpointMock(server, {
|
|
113
|
+
method: "post",
|
|
114
|
+
path: getSourceUrl(`deployment/{env}/${deploymentId}`),
|
|
115
|
+
...mockParams
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function mockRollbackDeployment(
|
|
120
|
+
server: SetupServer,
|
|
121
|
+
params: MockParams<Awaited<ReturnType<typeof rollbackDeployment>>>
|
|
122
|
+
) {
|
|
123
|
+
return generateEndpointMock(server, {
|
|
124
|
+
...params,
|
|
125
|
+
method: "delete",
|
|
126
|
+
path: getSourceUrl("deployment/{env}")
|
|
127
|
+
})
|
|
128
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
|
|
3
|
+
import { isValidAlphaNumeric } from "#utils/validations.ts"
|
|
4
|
+
|
|
5
|
+
describe("isValidAlphaNumeric", () => {
|
|
6
|
+
it("should accept valid alphanumeric strings", () => {
|
|
7
|
+
expect(isValidAlphaNumeric("Test deployment")).toBe(true)
|
|
8
|
+
expect(isValidAlphaNumeric("My deployment 123")).toBe(true)
|
|
9
|
+
expect(isValidAlphaNumeric("Production-v1.2.3")).toBe(true)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it("should accept strings with allowed special characters", () => {
|
|
13
|
+
expect(isValidAlphaNumeric("Test-deployment_v1.0")).toBe(true)
|
|
14
|
+
expect(isValidAlphaNumeric("What is this?")).toBe(true)
|
|
15
|
+
expect(isValidAlphaNumeric("Hello, world!")).toBe(true)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it("should reject strings longer than 200 characters", () => {
|
|
19
|
+
const longString = "a".repeat(201)
|
|
20
|
+
expect(isValidAlphaNumeric(longString)).toBe(false)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it("should accept strings up to 200 characters", () => {
|
|
24
|
+
const maxString = "a".repeat(200)
|
|
25
|
+
expect(isValidAlphaNumeric(maxString)).toBe(true)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it("should reject empty strings", () => {
|
|
29
|
+
expect(isValidAlphaNumeric("")).toBe(false)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it("should reject non-string values", () => {
|
|
33
|
+
expect(isValidAlphaNumeric(null)).toBe(false)
|
|
34
|
+
expect(isValidAlphaNumeric(undefined)).toBe(false)
|
|
35
|
+
expect(isValidAlphaNumeric(123)).toBe(false)
|
|
36
|
+
expect(isValidAlphaNumeric({})).toBe(false)
|
|
37
|
+
expect(isValidAlphaNumeric([])).toBe(false)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it("should reject strings with disallowed special characters", () => {
|
|
41
|
+
expect(isValidAlphaNumeric("test@deployment")).toBe(false)
|
|
42
|
+
expect(isValidAlphaNumeric("test#deployment")).toBe(false)
|
|
43
|
+
expect(isValidAlphaNumeric("test$deployment")).toBe(false)
|
|
44
|
+
expect(isValidAlphaNumeric("test%deployment")).toBe(false)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it("should accept strings with spaces", () => {
|
|
48
|
+
expect(isValidAlphaNumeric("This is a test")).toBe(true)
|
|
49
|
+
expect(isValidAlphaNumeric("Multiple spaces")).toBe(true)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it("should reject strings with newlines", () => {
|
|
53
|
+
expect(isValidAlphaNumeric("Test\ndeployment")).toBe(false)
|
|
54
|
+
expect(isValidAlphaNumeric("Multiple\n\nlines")).toBe(false)
|
|
55
|
+
expect(isValidAlphaNumeric("Test\rdeployment")).toBe(false)
|
|
56
|
+
expect(isValidAlphaNumeric("Test\r\ndeployment")).toBe(false)
|
|
57
|
+
})
|
|
58
|
+
})
|