-
Notifications
You must be signed in to change notification settings - Fork 565
/
Copy pathtransformApiHandler.test.ts
161 lines (155 loc) · 6.93 KB
/
transformApiHandler.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import assert from 'assert'
import {
TransformationProgressUpdate,
TransformationStep,
findDownloadArtifactProgressUpdate,
findDownloadArtifactStep,
getArtifactsFromProgressUpdate,
} from 'aws-core-vscode/codewhisperer/node'
describe('Amazon Q Transform - transformApiHandler tests', function () {
describe('getArtifactIdentifiers', function () {
it('will return downloaded artifact values from transformationStep', function () {
const downloadArtifactId = 'hil-test-artifact-id'
const downloadArtifactType = 'BuiltJars'
const transformationStepsFixture: TransformationProgressUpdate = {
name: 'Status step',
status: 'FAILED',
description: 'This step should be hil identifier',
startTime: new Date(),
endTime: new Date(),
downloadArtifacts: [
{
downloadArtifactId,
downloadArtifactType,
},
],
}
const { artifactId, artifactType } = getArtifactsFromProgressUpdate(transformationStepsFixture)
assert.strictEqual(artifactId, downloadArtifactId)
assert.strictEqual(artifactType, downloadArtifactType)
})
})
describe('findDownloadArtifactStep', function () {
it('will return downloaded artifact values from transformationStep', function () {
const downloadArtifactId = 'hil-test-artifact-id'
const downloadArtifactType = 'BuiltJars'
const transformationStepsFixture: TransformationStep[] = [
{
id: 'fake-step-id-1',
name: 'Building Code',
description: 'Building dependencies',
status: 'COMPLETED',
progressUpdates: [
{
name: 'Status step',
status: 'FAILED',
description: 'This step should be hil identifier',
startTime: new Date(),
endTime: new Date(),
downloadArtifacts: [
{
downloadArtifactId,
downloadArtifactType,
},
],
},
],
startTime: new Date(),
endTime: new Date(),
},
]
const { transformationStep, progressUpdate } = findDownloadArtifactStep(transformationStepsFixture)
assert.strictEqual(transformationStep, transformationStepsFixture[0])
assert.strictEqual(progressUpdate, transformationStepsFixture[0].progressUpdates?.[0])
})
it('will return undefined if no downloadArtifactId found', function () {
const transformationStepsFixture: TransformationStep[] = [
{
id: 'fake-step-id-1',
name: 'Building Code',
description: 'Building dependencies',
status: 'COMPLETED',
progressUpdates: [
{
name: 'Status step',
status: 'FAILED',
description: 'This step should be hil identifier',
startTime: new Date(),
endTime: new Date(),
downloadArtifacts: undefined,
},
],
startTime: new Date(),
endTime: new Date(),
},
]
const { transformationStep, progressUpdate } = findDownloadArtifactStep(transformationStepsFixture)
assert.strictEqual(transformationStep, undefined)
assert.strictEqual(progressUpdate, undefined)
})
})
describe('findDownloadArtifactProgressUpdate', function () {
it('will return correct progress update from transformationStep', function () {
const transformationStepsFixture: TransformationStep[] = [
{
id: 'dummy-id',
name: 'Step name',
description: 'Step description',
status: 'TRANSFORMING',
progressUpdates: [
{
name: 'Progress update name',
status: 'AWAITING_CLIENT_ACTION',
description: 'Client-side build happening now',
startTime: new Date(),
endTime: new Date(),
downloadArtifacts: [
{
downloadArtifactId: 'some-download-artifact-id',
downloadArtifactType: 'some-download-artifact-type',
},
],
},
],
startTime: new Date(),
endTime: new Date(),
},
]
const progressUpdate = findDownloadArtifactProgressUpdate(transformationStepsFixture)
assert.strictEqual(progressUpdate, transformationStepsFixture[0].progressUpdates?.[0])
})
it('will return undefined if step status is NOT AWAITING_CLIENT_ACTION', function () {
const transformationStepsFixture: TransformationStep[] = [
{
id: 'dummy-id',
name: 'Step name',
description: 'Step description',
status: 'TRANSFORMING',
progressUpdates: [
{
name: 'Progress update name',
status: 'SOMETHING-BESIDES-AWAITING_CLIENT_ACTION',
description: 'Progress update description',
startTime: new Date(),
endTime: new Date(),
downloadArtifacts: [
{
downloadArtifactId: 'some-download-artifact-id',
downloadArtifactType: 'some-download-artifact-type',
},
],
},
],
startTime: new Date(),
endTime: new Date(),
},
]
const progressUpdate = findDownloadArtifactProgressUpdate(transformationStepsFixture)
assert.strictEqual(progressUpdate, undefined)
})
})
})