@@ -41,5 +41,129 @@ describe('remote change sort', () => {
4141 remoteChange . sort ( changes )
4242 changes . should . deepEqual ( [ deleted , created ] )
4343 } )
44+
45+ it ( 'even with other changes' , ( ) => {
46+ const netflixBillAddition = {
47+ doc : {
48+ path : 'Administratif/Netflix/email_2/2019-05-06_12,34.pdf'
49+ } ,
50+ was : null ,
51+ type : 'FileAddition'
52+ }
53+ const edfContract1ConflictCreation = {
54+ doc : {
55+ path :
56+ 'Administratif/EDF/email_1/Address 1/attestation de contrat-conflict-2019-05-06T12_34_56.012Z.pdf'
57+ } ,
58+ was : {
59+ path : 'Administratif/EDF/email_1/Address 1/attestation de contrat.pdf'
60+ } ,
61+ type : 'FileMove'
62+ }
63+ const edfContract2ConflictCreation = {
64+ doc : {
65+ path :
66+ 'Administratif/EDF/email_1/Address 3/attestation de contrat-conflict-2019-05-06T12_34_56.345Z.pdf'
67+ } ,
68+ was : {
69+ path : 'Administratif/EDF/email_1/Address 3/attestation de contrat.pdf'
70+ } ,
71+ type : 'FileMove'
72+ }
73+ const edfContract3Deletion = {
74+ doc : {
75+ path : 'Administratif/EDF/email_2/Address 2/attestation de contrat.pdf'
76+ } ,
77+ was : {
78+ path : 'Administratif/EDF/email_2/Address 2/attestation de contrat.pdf'
79+ } ,
80+ type : 'FileDeletion'
81+ }
82+ const edfContract3Addition = {
83+ doc : {
84+ path : 'Administratif/EDF/email_2/Address 2/attestation de contrat.pdf'
85+ } ,
86+ was : null ,
87+ type : 'FileAddition'
88+ }
89+ const edfContract2Addition = {
90+ doc : {
91+ path : 'Administratif/EDF/email_1/Address 3/attestation de contrat.pdf'
92+ } ,
93+ was : null ,
94+ type : 'FileAddition'
95+ }
96+ const edfContract1Addition = {
97+ doc : {
98+ path : 'Administratif/EDF/email_1/Address 1/attestation de contrat.pdf'
99+ } ,
100+ was : null ,
101+ type : 'FileAddition'
102+ }
103+ const digipostBouyguesBill = {
104+ doc : {
105+ path :
106+ 'Administratif/Digiposte/email_2/Bouygues Telecom - Factures/Facture_2019-05-06.pdf'
107+ } ,
108+ was : null ,
109+ type : 'FileAddition'
110+ }
111+ const alanInsuranceCardDeletion = {
112+ doc : {
113+ path : 'Administratif/Alan/email_2/Carte_Mutuelle.pdf'
114+ } ,
115+ was : {
116+ path : 'Administratif/Alan/email_2/Carte_Mutuelle.pdf'
117+ } ,
118+ type : 'FileDeletion'
119+ }
120+ const alanInsuranceCardAddition = {
121+ doc : {
122+ path : 'Administratif/Alan/email_2/Carte_Mutuelle.pdf'
123+ } ,
124+ was : null ,
125+ type : 'FileAddition'
126+ }
127+ const photoAddition = {
128+ doc : {
129+ path : 'Photos/Sauvegardées depuis mon mobile/20190506_123456.jpg'
130+ } ,
131+ was : null ,
132+ type : 'FileAddition'
133+ }
134+
135+ const changes = [
136+ netflixBillAddition ,
137+ edfContract1ConflictCreation ,
138+ edfContract2ConflictCreation ,
139+ edfContract3Deletion ,
140+ edfContract3Addition ,
141+ edfContract2Addition ,
142+ edfContract1Addition ,
143+ digipostBouyguesBill ,
144+ alanInsuranceCardDeletion ,
145+ alanInsuranceCardAddition ,
146+ photoAddition
147+ ]
148+ remoteChange . sort ( changes )
149+
150+ // Sort order:
151+ // - alphabetical order
152+ // - conflicts before anything else on same id
153+ // - deletion before addition on same id
154+ changes . should . deepEqual ( [
155+ alanInsuranceCardDeletion ,
156+ alanInsuranceCardAddition ,
157+ digipostBouyguesBill ,
158+ edfContract1ConflictCreation ,
159+ edfContract1Addition ,
160+ edfContract2ConflictCreation ,
161+ edfContract2Addition ,
162+ edfContract3Deletion ,
163+ edfContract3Addition ,
164+ netflixBillAddition ,
165+ photoAddition
166+ ] )
167+ } )
44168 } )
45169} )
0 commit comments