@@ -90,6 +90,41 @@ func TestAccountHandlerSyncRepository(t *testing.T) {
9090 tearDown ()
9191 })
9292
93+ t .Run ("Should sync successfully after account reactivation when it was pending" , func (t * testing.T ) {
94+ // Given
95+ fakeGitService := NewFakeGitService ()
96+ fakeApiService := NewFakeApiService ()
97+ fakeApiService .pushChanges = PushChangeResponse {
98+ Message : "Changes applied successfully" ,
99+ Version : 1 ,
100+ }
101+ coreHandler = NewCoreHandler (coreHandler .accountRepository , fakeApiService , NewComparatorService ())
102+
103+ account := givenAccount ()
104+ account .Domain .ID = "123-pending"
105+ account .Domain .Status = model .StatusPending
106+ account .Domain .Message = "Account was deactivated"
107+ account .Domain .LastCommit = "123"
108+ account .Domain .Version = 1
109+ accountCreated , _ := coreHandler .accountRepository .Create (& account )
110+
111+ // Test
112+ go coreHandler .StartAccountHandler (accountCreated .ID .Hex (), fakeGitService )
113+
114+ // Wait for goroutine to process
115+ time .Sleep (1 * time .Second )
116+
117+ // Assert
118+ accountFromDb , _ := coreHandler .accountRepository .FetchByAccountId (string (accountCreated .ID .Hex ()))
119+ assert .Equal (t , model .StatusSynced , accountFromDb .Domain .Status )
120+ assert .Contains (t , accountFromDb .Domain .Message , model .MessageSynced )
121+ assert .Equal (t , "123" , accountFromDb .Domain .LastCommit )
122+ assert .Equal (t , 1 , accountFromDb .Domain .Version )
123+ assert .NotEqual (t , "" , accountFromDb .Domain .LastDate )
124+
125+ tearDown ()
126+ })
127+
93128 t .Run ("Should sync successfully when repository is out of sync" , func (t * testing.T ) {
94129 // Given
95130 fakeGitService := NewFakeGitService ()
@@ -309,6 +344,35 @@ func TestAccountHandlerNotSync(t *testing.T) {
309344 tearDown ()
310345 })
311346
347+ t .Run ("Should not sync when fetch repository data returns a malformed JSON content" , func (t * testing.T ) {
348+ // Given
349+ fakeGitService := NewFakeGitService ()
350+ fakeGitService .content = `{
351+ "domain": {
352+ "group": [{
353+ "name": "Release 1",
354+ "description": "Showcase configuration",
355+ "activated": true
356+ }`
357+
358+ account := givenAccount ()
359+ account .Domain .ID = "123-error-malformed-json"
360+ accountCreated , _ := coreHandler .accountRepository .Create (& account )
361+
362+ // Test
363+ go coreHandler .StartAccountHandler (accountCreated .ID .Hex (), fakeGitService )
364+
365+ time .Sleep (1 * time .Second )
366+
367+ // Assert
368+ accountFromDb , _ := coreHandler .accountRepository .FetchByDomainIdEnvironment (accountCreated .Domain .ID , accountCreated .Environment )
369+ assert .Equal (t , model .StatusError , accountFromDb .Domain .Status )
370+ assert .Contains (t , accountFromDb .Domain .Message , "Invalid JSON content" )
371+ assert .Equal (t , "" , accountFromDb .Domain .LastCommit )
372+
373+ tearDown ()
374+ })
375+
312376 t .Run ("Should not sync when fetch snapshot version returns an error" , func (t * testing.T ) {
313377 // Given
314378 fakeGitService := NewFakeGitService ()
0 commit comments