|
| 1 | +import { describe, test, expect } from "vitest"; |
| 2 | +import { detectVersionBump } from "../detectVersionBump.js"; |
| 3 | +import type { SpecChangeSet } from "../diffChangeSet.js"; |
| 4 | + |
| 5 | +describe("detectVersionBump", () => { |
| 6 | + describe("none", () => { |
| 7 | + test("변경사항이 없으면 none을 반환한다", () => { |
| 8 | + const changeSet: SpecChangeSet = { |
| 9 | + baseHash: "abc", |
| 10 | + headHash: "abc", |
| 11 | + changes: [], |
| 12 | + }; |
| 13 | + |
| 14 | + const result = detectVersionBump(changeSet); |
| 15 | + |
| 16 | + expect(result.recommendedBump).toBe("none"); |
| 17 | + expect(result.isBreaking).toBe(false); |
| 18 | + expect(result.reasons).toHaveLength(0); |
| 19 | + }); |
| 20 | + }); |
| 21 | + |
| 22 | + describe("major (breaking changes)", () => { |
| 23 | + test("removed 타입은 major를 반환한다", () => { |
| 24 | + const changeSet: SpecChangeSet = { |
| 25 | + baseHash: "abc", |
| 26 | + headHash: "def", |
| 27 | + changes: [ |
| 28 | + { |
| 29 | + type: "removed", |
| 30 | + path: [], |
| 31 | + key: "GET /users", |
| 32 | + baseHash: "hash1", |
| 33 | + }, |
| 34 | + ], |
| 35 | + }; |
| 36 | + |
| 37 | + const result = detectVersionBump(changeSet); |
| 38 | + |
| 39 | + expect(result.recommendedBump).toBe("major"); |
| 40 | + expect(result.isBreaking).toBe(true); |
| 41 | + expect(result.reasons).toHaveLength(1); |
| 42 | + }); |
| 43 | + |
| 44 | + test("type_changed는 major를 반환한다", () => { |
| 45 | + const changeSet: SpecChangeSet = { |
| 46 | + baseHash: "abc", |
| 47 | + headHash: "def", |
| 48 | + changes: [ |
| 49 | + { |
| 50 | + type: "type_changed", |
| 51 | + path: [], |
| 52 | + key: "GET /users", |
| 53 | + baseHash: "hash1", |
| 54 | + headHash: "hash2", |
| 55 | + baseNodeType: "leaf", |
| 56 | + headNodeType: "node", |
| 57 | + }, |
| 58 | + ], |
| 59 | + }; |
| 60 | + |
| 61 | + const result = detectVersionBump(changeSet); |
| 62 | + |
| 63 | + expect(result.recommendedBump).toBe("major"); |
| 64 | + expect(result.isBreaking).toBe(true); |
| 65 | + expect(result.reasons).toHaveLength(1); |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + describe("minor", () => { |
| 70 | + test("added 타입은 minor를 반환한다", () => { |
| 71 | + const changeSet: SpecChangeSet = { |
| 72 | + baseHash: "abc", |
| 73 | + headHash: "def", |
| 74 | + changes: [ |
| 75 | + { |
| 76 | + type: "added", |
| 77 | + path: [], |
| 78 | + key: "POST /users", |
| 79 | + headHash: "hash1", |
| 80 | + }, |
| 81 | + ], |
| 82 | + }; |
| 83 | + |
| 84 | + const result = detectVersionBump(changeSet); |
| 85 | + |
| 86 | + expect(result.recommendedBump).toBe("minor"); |
| 87 | + expect(result.isBreaking).toBe(false); |
| 88 | + expect(result.reasons).toHaveLength(1); |
| 89 | + }); |
| 90 | + |
| 91 | + test("modified 타입은 minor를 반환한다", () => { |
| 92 | + const changeSet: SpecChangeSet = { |
| 93 | + baseHash: "abc", |
| 94 | + headHash: "def", |
| 95 | + changes: [ |
| 96 | + { |
| 97 | + type: "modified", |
| 98 | + path: [], |
| 99 | + key: "GET /users", |
| 100 | + baseHash: "hash1", |
| 101 | + headHash: "hash2", |
| 102 | + }, |
| 103 | + ], |
| 104 | + }; |
| 105 | + |
| 106 | + const result = detectVersionBump(changeSet); |
| 107 | + |
| 108 | + expect(result.recommendedBump).toBe("minor"); |
| 109 | + expect(result.isBreaking).toBe(false); |
| 110 | + expect(result.reasons).toHaveLength(1); |
| 111 | + }); |
| 112 | + }); |
| 113 | + |
| 114 | + describe("patch", () => { |
| 115 | + // TODO: Operation 내부 변경 분석 기능 추가 시 patch 케이스 개선 필요 |
| 116 | + // (현재는 알 수 없는 ChangeType만 patch로 분류됨) |
| 117 | + test("알 수 없는 타입은 patch를 반환한다", () => { |
| 118 | + const changeSet: SpecChangeSet = { |
| 119 | + baseHash: "abc", |
| 120 | + headHash: "def", |
| 121 | + changes: [ |
| 122 | + { |
| 123 | + type: "unknown" as any, |
| 124 | + path: [], |
| 125 | + key: "GET /users", |
| 126 | + }, |
| 127 | + ], |
| 128 | + }; |
| 129 | + |
| 130 | + const result = detectVersionBump(changeSet); |
| 131 | + |
| 132 | + expect(result.recommendedBump).toBe("patch"); |
| 133 | + expect(result.isBreaking).toBe(false); |
| 134 | + expect(result.reasons).toHaveLength(1); |
| 135 | + }); |
| 136 | + }); |
| 137 | + |
| 138 | + describe("version bump 우선순위", () => { |
| 139 | + test("major > minor: major가 있으면 major를 반환한다", () => { |
| 140 | + const changeSet: SpecChangeSet = { |
| 141 | + baseHash: "abc", |
| 142 | + headHash: "def", |
| 143 | + changes: [ |
| 144 | + { |
| 145 | + type: "added", |
| 146 | + path: [], |
| 147 | + key: "POST /users", |
| 148 | + headHash: "hash1", |
| 149 | + }, |
| 150 | + { |
| 151 | + type: "removed", |
| 152 | + path: [], |
| 153 | + key: "DELETE /users", |
| 154 | + baseHash: "hash2", |
| 155 | + }, |
| 156 | + ], |
| 157 | + }; |
| 158 | + |
| 159 | + const result = detectVersionBump(changeSet); |
| 160 | + |
| 161 | + expect(result.recommendedBump).toBe("major"); |
| 162 | + expect(result.isBreaking).toBe(true); |
| 163 | + expect(result.reasons).toHaveLength(2); |
| 164 | + }); |
| 165 | + |
| 166 | + test("reasons에는 해당 레벨의 모든 변경 이유가 포함된다", () => { |
| 167 | + const changeSet: SpecChangeSet = { |
| 168 | + baseHash: "abc", |
| 169 | + headHash: "def", |
| 170 | + changes: [ |
| 171 | + { |
| 172 | + type: "removed", |
| 173 | + path: [], |
| 174 | + key: "DELETE /users", |
| 175 | + baseHash: "hash1", |
| 176 | + }, |
| 177 | + { |
| 178 | + type: "removed", |
| 179 | + path: [], |
| 180 | + key: "DELETE /posts", |
| 181 | + baseHash: "hash2", |
| 182 | + }, |
| 183 | + ], |
| 184 | + }; |
| 185 | + |
| 186 | + const result = detectVersionBump(changeSet); |
| 187 | + |
| 188 | + expect(result.reasons).toHaveLength(2); |
| 189 | + }); |
| 190 | + }); |
| 191 | +}); |
0 commit comments