@@ -3,6 +3,8 @@ import { run } from './utils/run.js';
33import { TolgeeClient } from '#cli/client/TolgeeClient.js' ;
44import { PROJECT_2 } from './utils/api/project2.js' ;
55import {
6+ createBranch ,
7+ createKey ,
68 createPak ,
79 createProjectWithClient ,
810 deleteProject ,
@@ -34,7 +36,7 @@ const CODE_UNORDERED = fileURLToPathSlash(
3436let client : TolgeeClient ;
3537let pak : string ;
3638
37- describe ( 'Project 1 ' , ( ) => {
39+ describe ( 'Project 2 ' , ( ) => {
3840 beforeEach ( async ( ) => {
3941 client = await createProjectWithClient ( 'Project 2' , PROJECT_2 ) ;
4042 pak = await createPak ( client ) ;
@@ -106,12 +108,12 @@ describe('Project 1', () => {
106108 expect ( out . code ) . toBe ( 0 ) ;
107109
108110 // Test all added keys
109- expect ( out . stdout ) . toContain ( 'section-content' ) ;
110- expect ( out . stdout ) . toContain ( 'section-title' ) ;
111- expect ( out . stdout ) . toContain ( 'copyright-notice' ) ;
112- expect ( out . stdout ) . toContain ( 'privacy-policy' ) ;
113- expect ( out . stdout ) . toContain ( 'terms-of-service' ) ;
114- expect ( out . stdout ) . toContain ( 'welcome' ) ;
111+ expect ( out . stdout ) . toContain ( '+ section-content' ) ;
112+ expect ( out . stdout ) . toContain ( '+ section-title' ) ;
113+ expect ( out . stdout ) . toContain ( '+ copyright-notice' ) ;
114+ expect ( out . stdout ) . toContain ( '+ privacy-policy' ) ;
115+ expect ( out . stdout ) . toContain ( '+ terms-of-service' ) ;
116+ expect ( out . stdout ) . toContain ( '+ welcome' ) ;
115117
116118 expect ( out . stdout . indexOf ( 'section-content' ) ) . toBeLessThan (
117119 out . stdout . indexOf ( 'section-title' )
@@ -130,12 +132,12 @@ describe('Project 1', () => {
130132 ) ;
131133
132134 // Test all removed keys
133- expect ( out . stdout ) . toContain ( 'bird-name' ) ;
134- expect ( out . stdout ) . toContain ( 'bird-sound' ) ;
135- expect ( out . stdout ) . toContain ( 'cat-name' ) ;
136- expect ( out . stdout ) . toContain ( 'cat-sound' ) ;
137- expect ( out . stdout ) . toContain ( 'dog-name' ) ;
138- expect ( out . stdout ) . toContain ( 'dog-sound' ) ;
135+ expect ( out . stdout ) . toContain ( '- bird-name' ) ;
136+ expect ( out . stdout ) . toContain ( '- bird-sound' ) ;
137+ expect ( out . stdout ) . toContain ( '- cat-name' ) ;
138+ expect ( out . stdout ) . toContain ( '- cat-sound' ) ;
139+ expect ( out . stdout ) . toContain ( '- dog-name' ) ;
140+ expect ( out . stdout ) . toContain ( '- dog-sound' ) ;
139141
140142 expect ( out . stdout . indexOf ( 'bird-name' ) ) . toBeLessThan (
141143 out . stdout . indexOf ( 'bird-sound' )
@@ -155,6 +157,78 @@ describe('Project 1', () => {
155157 } , 30e3 ) ;
156158} ) ;
157159
160+ describe ( 'Branching' , ( ) => {
161+ beforeEach ( async ( ) => {
162+ client = await createProjectWithClient ( 'Project 2' , PROJECT_2 ) ;
163+ pak = await createPak ( client ) ;
164+
165+ await createBranch ( client , 'feature-branch' ) ;
166+
167+ await createKey ( client , 'mouse-name' , {
168+ branch : 'feature-branch' ,
169+ translations : { en : 'Mouse' } ,
170+ } ) ;
171+ await createKey ( client , 'mouse-sound' , {
172+ branch : 'feature-branch' ,
173+ translations : { en : 'Squeek' } ,
174+ } ) ;
175+ } ) ;
176+
177+ afterEach ( async ( ) => {
178+ await deleteProject ( client ) ;
179+ } ) ;
180+
181+ it ( 'contains added keys in new branch' , async ( ) => {
182+ const out = await run (
183+ [
184+ 'compare' ,
185+ '--api-key' ,
186+ pak ,
187+ '--patterns' ,
188+ CODE_PROJECT_2_ADDED ,
189+ '--branch' ,
190+ 'feature-branch' ,
191+ ] ,
192+ undefined ,
193+ 20e3
194+ ) ;
195+
196+ expect ( out . code ) . toBe ( 0 ) ;
197+ expect ( out . stdout ) . toContain ( 'is in sync' ) ;
198+ } ) ;
199+
200+ it ( 'does not contain the added keys in main branch' , async ( ) => {
201+ const out = await run (
202+ [ 'compare' , '--api-key' , pak , '--patterns' , CODE_PROJECT_2_ADDED ] ,
203+ undefined ,
204+ 20e3
205+ ) ;
206+
207+ expect ( out . code ) . toBe ( 0 ) ;
208+ expect ( out . stdout ) . toContain ( 'out of sync' ) ;
209+ expect ( out . stdout ) . toContain ( '2 new keys found' ) ;
210+ } , 30e3 ) ;
211+
212+ it ( 'fails when branch does not exist' , async ( ) => {
213+ const out = await run (
214+ [
215+ 'compare' ,
216+ '--api-key' ,
217+ pak ,
218+ '--patterns' ,
219+ CODE_PROJECT_2_COMPLETE ,
220+ '--branch' ,
221+ 'missing-branch' ,
222+ ] ,
223+ undefined ,
224+ 20e3
225+ ) ;
226+
227+ expect ( out . code ) . not . toBe ( 0 ) ;
228+ expect ( out . stderr + out . stdout ) . toContain ( 'branch_not_found' ) ;
229+ } , 30e3 ) ;
230+ } ) ;
231+
158232describe ( 'Project 3' , ( ) => {
159233 beforeEach ( async ( ) => {
160234 client = await createProjectWithClient ( 'Project 3' , PROJECT_3 ) ;
0 commit comments