|
| 1 | +import { ApiProperty } from '@nestjs/swagger'; |
| 2 | +import { Build, TestRun, TestStatus } from '@prisma/client'; |
| 3 | +import { BuildDto } from './build.dto'; |
| 4 | + |
| 5 | +describe('BuildDto', () => { |
| 6 | + it.each([ |
| 7 | + [ |
| 8 | + 'undefined testRuns', |
| 9 | + { |
| 10 | + id: 'a9385fc1-884d-4f9f-915e-40da0e7773d5', |
| 11 | + number: null, |
| 12 | + branchName: 'develop', |
| 13 | + status: null, |
| 14 | + projectId: 'e0a37894-6f29-478d-b13e-6182fecc715e', |
| 15 | + updatedAt: new Date(), |
| 16 | + createdAt: new Date(), |
| 17 | + userId: null, |
| 18 | + testRuns: undefined, |
| 19 | + }, |
| 20 | + ], |
| 21 | + [ |
| 22 | + 'empty testRuns', |
| 23 | + { |
| 24 | + id: 'a9385fc1-884d-4f9f-915e-40da0e7773d5', |
| 25 | + number: null, |
| 26 | + branchName: 'develop', |
| 27 | + status: null, |
| 28 | + projectId: 'e0a37894-6f29-478d-b13e-6182fecc715e', |
| 29 | + updatedAt: new Date(), |
| 30 | + createdAt: new Date(), |
| 31 | + userId: null, |
| 32 | + testRuns: [], |
| 33 | + }, |
| 34 | + ], |
| 35 | + ])('new with %s', (_, build) => { |
| 36 | + const buildDto: BuildDto = { |
| 37 | + id: build.id, |
| 38 | + number: build.number, |
| 39 | + branchName: build.branchName, |
| 40 | + status: 'new', |
| 41 | + projectId: build.projectId, |
| 42 | + updatedAt: build.updatedAt, |
| 43 | + createdAt: build.createdAt, |
| 44 | + userId: null, |
| 45 | + passedCount: 0, |
| 46 | + unresolvedCount: 0, |
| 47 | + failedCount: 0, |
| 48 | + }; |
| 49 | + |
| 50 | + const result = new BuildDto(build); |
| 51 | + |
| 52 | + expect(result).toEqual(buildDto); |
| 53 | + }); |
| 54 | + |
| 55 | + it('passed', () => { |
| 56 | + const build = { |
| 57 | + id: 'a9385fc1-884d-4f9f-915e-40da0e7773d5', |
| 58 | + number: null, |
| 59 | + branchName: 'develop', |
| 60 | + status: null, |
| 61 | + projectId: 'e0a37894-6f29-478d-b13e-6182fecc715e', |
| 62 | + updatedAt: new Date(), |
| 63 | + createdAt: new Date(), |
| 64 | + userId: null, |
| 65 | + testRuns: [ |
| 66 | + { |
| 67 | + id: '10fb5e02-64e0-4cf5-9f17-c00ab3c96658', |
| 68 | + imageName: '1592423768112.screenshot.png', |
| 69 | + diffName: null, |
| 70 | + diffPercent: null, |
| 71 | + diffTollerancePercent: 1, |
| 72 | + pixelMisMatchCount: null, |
| 73 | + status: TestStatus.ok, |
| 74 | + buildId: '146e7a8d-89f0-4565-aa2c-e61efabb0afd', |
| 75 | + testVariationId: '3bc4a5bc-006e-4d43-8e4e-eaa132627fca', |
| 76 | + updatedAt: new Date(), |
| 77 | + createdAt: new Date(), |
| 78 | + name: 'ss2f77', |
| 79 | + browser: 'chromium', |
| 80 | + device: null, |
| 81 | + os: null, |
| 82 | + viewport: '1800x1600', |
| 83 | + baselineName: null, |
| 84 | + ignoreAreas: '[]', |
| 85 | + }, |
| 86 | + { |
| 87 | + id: '10fb5e02-64e0-4cf5-9f17-c00ab3c96658', |
| 88 | + imageName: '1592423768112.screenshot.png', |
| 89 | + diffName: null, |
| 90 | + diffPercent: null, |
| 91 | + diffTollerancePercent: 1, |
| 92 | + pixelMisMatchCount: null, |
| 93 | + status: TestStatus.approved, |
| 94 | + buildId: '146e7a8d-89f0-4565-aa2c-e61efabb0afd', |
| 95 | + testVariationId: '3bc4a5bc-006e-4d43-8e4e-eaa132627fca', |
| 96 | + updatedAt: new Date(), |
| 97 | + createdAt: new Date(), |
| 98 | + name: 'ss2f77', |
| 99 | + browser: 'chromium', |
| 100 | + device: null, |
| 101 | + os: null, |
| 102 | + viewport: '1800x1600', |
| 103 | + baselineName: null, |
| 104 | + ignoreAreas: '[]', |
| 105 | + }, |
| 106 | + ], |
| 107 | + }; |
| 108 | + const buildDto: BuildDto = { |
| 109 | + id: build.id, |
| 110 | + number: build.number, |
| 111 | + branchName: build.branchName, |
| 112 | + status: 'passed', |
| 113 | + projectId: build.projectId, |
| 114 | + updatedAt: build.updatedAt, |
| 115 | + createdAt: build.createdAt, |
| 116 | + userId: null, |
| 117 | + passedCount: 2, |
| 118 | + unresolvedCount: 0, |
| 119 | + failedCount: 0, |
| 120 | + }; |
| 121 | + |
| 122 | + const result = new BuildDto(build); |
| 123 | + |
| 124 | + expect(result).toEqual(buildDto); |
| 125 | + }); |
| 126 | + |
| 127 | + it('failed', () => { |
| 128 | + const build = { |
| 129 | + id: 'a9385fc1-884d-4f9f-915e-40da0e7773d5', |
| 130 | + number: null, |
| 131 | + branchName: 'develop', |
| 132 | + status: null, |
| 133 | + projectId: 'e0a37894-6f29-478d-b13e-6182fecc715e', |
| 134 | + updatedAt: new Date(), |
| 135 | + createdAt: new Date(), |
| 136 | + userId: null, |
| 137 | + testRuns: [ |
| 138 | + { |
| 139 | + id: '10fb5e02-64e0-4cf5-9f17-c00ab3c96658', |
| 140 | + imageName: '1592423768112.screenshot.png', |
| 141 | + diffName: null, |
| 142 | + diffPercent: null, |
| 143 | + diffTollerancePercent: 1, |
| 144 | + pixelMisMatchCount: null, |
| 145 | + status: TestStatus.ok, |
| 146 | + buildId: '146e7a8d-89f0-4565-aa2c-e61efabb0afd', |
| 147 | + testVariationId: '3bc4a5bc-006e-4d43-8e4e-eaa132627fca', |
| 148 | + updatedAt: new Date(), |
| 149 | + createdAt: new Date(), |
| 150 | + name: 'ss2f77', |
| 151 | + browser: 'chromium', |
| 152 | + device: null, |
| 153 | + os: null, |
| 154 | + viewport: '1800x1600', |
| 155 | + baselineName: null, |
| 156 | + ignoreAreas: '[]', |
| 157 | + }, |
| 158 | + { |
| 159 | + id: '10fb5e02-64e0-4cf5-9f17-c00ab3c96658', |
| 160 | + imageName: '1592423768112.screenshot.png', |
| 161 | + diffName: null, |
| 162 | + diffPercent: null, |
| 163 | + diffTollerancePercent: 1, |
| 164 | + pixelMisMatchCount: null, |
| 165 | + status: TestStatus.approved, |
| 166 | + buildId: '146e7a8d-89f0-4565-aa2c-e61efabb0afd', |
| 167 | + testVariationId: '3bc4a5bc-006e-4d43-8e4e-eaa132627fca', |
| 168 | + updatedAt: new Date(), |
| 169 | + createdAt: new Date(), |
| 170 | + name: 'ss2f77', |
| 171 | + browser: 'chromium', |
| 172 | + device: null, |
| 173 | + os: null, |
| 174 | + viewport: '1800x1600', |
| 175 | + baselineName: null, |
| 176 | + ignoreAreas: '[]', |
| 177 | + }, |
| 178 | + { |
| 179 | + id: '10fb5e02-64e0-4cf5-9f17-c00ab3c96658', |
| 180 | + imageName: '1592423768112.screenshot.png', |
| 181 | + diffName: null, |
| 182 | + diffPercent: null, |
| 183 | + diffTollerancePercent: 1, |
| 184 | + pixelMisMatchCount: null, |
| 185 | + status: TestStatus.failed, |
| 186 | + buildId: '146e7a8d-89f0-4565-aa2c-e61efabb0afd', |
| 187 | + testVariationId: '3bc4a5bc-006e-4d43-8e4e-eaa132627fca', |
| 188 | + updatedAt: new Date(), |
| 189 | + createdAt: new Date(), |
| 190 | + name: 'ss2f77', |
| 191 | + browser: 'chromium', |
| 192 | + device: null, |
| 193 | + os: null, |
| 194 | + viewport: '1800x1600', |
| 195 | + baselineName: null, |
| 196 | + ignoreAreas: '[]', |
| 197 | + }, |
| 198 | + ], |
| 199 | + }; |
| 200 | + const buildDto: BuildDto = { |
| 201 | + id: build.id, |
| 202 | + number: build.number, |
| 203 | + branchName: build.branchName, |
| 204 | + status: 'failed', |
| 205 | + projectId: build.projectId, |
| 206 | + updatedAt: build.updatedAt, |
| 207 | + createdAt: build.createdAt, |
| 208 | + userId: null, |
| 209 | + passedCount: 2, |
| 210 | + unresolvedCount: 0, |
| 211 | + failedCount: 1, |
| 212 | + }; |
| 213 | + |
| 214 | + const result = new BuildDto(build); |
| 215 | + |
| 216 | + expect(result).toEqual(buildDto); |
| 217 | + }); |
| 218 | + |
| 219 | + it('unresolved', () => { |
| 220 | + const build = { |
| 221 | + id: 'a9385fc1-884d-4f9f-915e-40da0e7773d5', |
| 222 | + number: null, |
| 223 | + branchName: 'develop', |
| 224 | + status: null, |
| 225 | + projectId: 'e0a37894-6f29-478d-b13e-6182fecc715e', |
| 226 | + updatedAt: new Date(), |
| 227 | + createdAt: new Date(), |
| 228 | + userId: null, |
| 229 | + testRuns: [ |
| 230 | + { |
| 231 | + id: '10fb5e02-64e0-4cf5-9f17-c00ab3c96658', |
| 232 | + imageName: '1592423768112.screenshot.png', |
| 233 | + diffName: null, |
| 234 | + diffPercent: null, |
| 235 | + diffTollerancePercent: 1, |
| 236 | + pixelMisMatchCount: null, |
| 237 | + status: TestStatus.ok, |
| 238 | + buildId: '146e7a8d-89f0-4565-aa2c-e61efabb0afd', |
| 239 | + testVariationId: '3bc4a5bc-006e-4d43-8e4e-eaa132627fca', |
| 240 | + updatedAt: new Date(), |
| 241 | + createdAt: new Date(), |
| 242 | + name: 'ss2f77', |
| 243 | + browser: 'chromium', |
| 244 | + device: null, |
| 245 | + os: null, |
| 246 | + viewport: '1800x1600', |
| 247 | + baselineName: null, |
| 248 | + ignoreAreas: '[]', |
| 249 | + }, |
| 250 | + { |
| 251 | + id: '10fb5e02-64e0-4cf5-9f17-c00ab3c96658', |
| 252 | + imageName: '1592423768112.screenshot.png', |
| 253 | + diffName: null, |
| 254 | + diffPercent: null, |
| 255 | + diffTollerancePercent: 1, |
| 256 | + pixelMisMatchCount: null, |
| 257 | + status: TestStatus.approved, |
| 258 | + buildId: '146e7a8d-89f0-4565-aa2c-e61efabb0afd', |
| 259 | + testVariationId: '3bc4a5bc-006e-4d43-8e4e-eaa132627fca', |
| 260 | + updatedAt: new Date(), |
| 261 | + createdAt: new Date(), |
| 262 | + name: 'ss2f77', |
| 263 | + browser: 'chromium', |
| 264 | + device: null, |
| 265 | + os: null, |
| 266 | + viewport: '1800x1600', |
| 267 | + baselineName: null, |
| 268 | + ignoreAreas: '[]', |
| 269 | + }, |
| 270 | + { |
| 271 | + id: '10fb5e02-64e0-4cf5-9f17-c00ab3c96658', |
| 272 | + imageName: '1592423768112.screenshot.png', |
| 273 | + diffName: null, |
| 274 | + diffPercent: null, |
| 275 | + diffTollerancePercent: 1, |
| 276 | + pixelMisMatchCount: null, |
| 277 | + status: TestStatus.failed, |
| 278 | + buildId: '146e7a8d-89f0-4565-aa2c-e61efabb0afd', |
| 279 | + testVariationId: '3bc4a5bc-006e-4d43-8e4e-eaa132627fca', |
| 280 | + updatedAt: new Date(), |
| 281 | + createdAt: new Date(), |
| 282 | + name: 'ss2f77', |
| 283 | + browser: 'chromium', |
| 284 | + device: null, |
| 285 | + os: null, |
| 286 | + viewport: '1800x1600', |
| 287 | + baselineName: null, |
| 288 | + ignoreAreas: '[]', |
| 289 | + }, |
| 290 | + { |
| 291 | + id: '10fb5e02-64e0-4cf5-9f17-c00ab3c96658', |
| 292 | + imageName: '1592423768112.screenshot.png', |
| 293 | + diffName: null, |
| 294 | + diffPercent: null, |
| 295 | + diffTollerancePercent: 1, |
| 296 | + pixelMisMatchCount: null, |
| 297 | + status: TestStatus.new, |
| 298 | + buildId: '146e7a8d-89f0-4565-aa2c-e61efabb0afd', |
| 299 | + testVariationId: '3bc4a5bc-006e-4d43-8e4e-eaa132627fca', |
| 300 | + updatedAt: new Date(), |
| 301 | + createdAt: new Date(), |
| 302 | + name: 'ss2f77', |
| 303 | + browser: 'chromium', |
| 304 | + device: null, |
| 305 | + os: null, |
| 306 | + viewport: '1800x1600', |
| 307 | + baselineName: null, |
| 308 | + ignoreAreas: '[]', |
| 309 | + }, |
| 310 | + { |
| 311 | + id: '10fb5e02-64e0-4cf5-9f17-c00ab3c96658', |
| 312 | + imageName: '1592423768112.screenshot.png', |
| 313 | + diffName: null, |
| 314 | + diffPercent: null, |
| 315 | + diffTollerancePercent: 1, |
| 316 | + pixelMisMatchCount: null, |
| 317 | + status: TestStatus.unresolved, |
| 318 | + buildId: '146e7a8d-89f0-4565-aa2c-e61efabb0afd', |
| 319 | + testVariationId: '3bc4a5bc-006e-4d43-8e4e-eaa132627fca', |
| 320 | + updatedAt: new Date(), |
| 321 | + createdAt: new Date(), |
| 322 | + name: 'ss2f77', |
| 323 | + browser: 'chromium', |
| 324 | + device: null, |
| 325 | + os: null, |
| 326 | + viewport: '1800x1600', |
| 327 | + baselineName: null, |
| 328 | + ignoreAreas: '[]', |
| 329 | + }, |
| 330 | + ], |
| 331 | + }; |
| 332 | + const buildDto: BuildDto = { |
| 333 | + id: build.id, |
| 334 | + number: build.number, |
| 335 | + branchName: build.branchName, |
| 336 | + status: 'unresolved', |
| 337 | + projectId: build.projectId, |
| 338 | + updatedAt: build.updatedAt, |
| 339 | + createdAt: build.createdAt, |
| 340 | + userId: null, |
| 341 | + passedCount: 2, |
| 342 | + unresolvedCount: 2, |
| 343 | + failedCount: 1, |
| 344 | + }; |
| 345 | + |
| 346 | + const result = new BuildDto(build); |
| 347 | + |
| 348 | + expect(result).toEqual(buildDto); |
| 349 | + }); |
| 350 | +}); |
0 commit comments