@@ -3,7 +3,7 @@ const assert = chai.assert;
3
3
var config = require ( 'config' ) ;
4
4
const API = require ( '../../api3.js' ) ;
5
5
const Helpers = require ( '../../helpers3.js' ) ;
6
- const { API3Before, API3After } = require ( "../shared.js" ) ;
6
+ const { API3Before, API3After, resetGroups } = require ( "../shared.js" ) ;
7
7
8
8
describe ( 'SortTests' , function ( ) {
9
9
this . timeout ( config . timeout ) ;
@@ -21,6 +21,7 @@ describe('SortTests', function () {
21
21
before ( async function ( ) {
22
22
await API3Before ( ) ;
23
23
await setup ( ) ;
24
+ await resetGroups ( ) ;
24
25
} ) ;
25
26
26
27
after ( async function ( ) {
@@ -76,6 +77,54 @@ describe('SortTests', function () {
76
77
}*/
77
78
} ;
78
79
80
+ it ( 'test_sort_group_by_editedBy' , async function ( ) {
81
+ // user 1 makes item
82
+ let jsonOne = await API . groupCreateItem (
83
+ config . ownedPrivateGroupID ,
84
+ 'book' ,
85
+ { title : `title_one` } ,
86
+ true ,
87
+ 'jsonData'
88
+ ) ;
89
+
90
+ API . useAPIKey ( config . user2APIKey ) ;
91
+
92
+ // user 2 makes item
93
+ let jsonTwo = await API . groupCreateItem (
94
+ config . ownedPrivateGroupID ,
95
+ 'book' ,
96
+ { title : `title_two` } ,
97
+ true ,
98
+ 'jsonData'
99
+ ) ;
100
+
101
+ // make sure, user's one item goes first
102
+ let response = await API . get ( `groups/${ config . ownedPrivateGroupID } /items?sort=editedBy&format=keys` ) ;
103
+ let sortedKeys = response . data . split ( '\n' ) ;
104
+ assert . equal ( sortedKeys [ 0 ] , jsonOne . key ) ;
105
+ assert . equal ( sortedKeys [ 1 ] , jsonTwo . key ) ;
106
+
107
+ // user 2 updates user1's item, and the other way around
108
+ response = await API . patch ( `groups/${ config . ownedPrivateGroupID } /items/${ jsonOne . key } ` ,
109
+ JSON . stringify ( { title : 'updated_by_user 2' } ) ,
110
+ { 'If-Unmodified-Since-Version' : jsonOne . version } ) ;
111
+
112
+ Helpers . assert204 ( response ) ;
113
+
114
+ API . useAPIKey ( config . apiKey ) ;
115
+
116
+ response = await API . patch ( `groups/${ config . ownedPrivateGroupID } /items/${ jsonTwo . key } ` ,
117
+ JSON . stringify ( { title : 'updated_by_user 2' } ) ,
118
+ { 'If-Unmodified-Since-Version' : jsonTwo . version } ) ;
119
+ Helpers . assert204 ( response ) ;
120
+
121
+ // now order should be switched
122
+ response = await API . get ( `groups/${ config . ownedPrivateGroupID } /items?sort=editedBy&format=keys` ) ;
123
+ sortedKeys = response . data . split ( '\n' ) ;
124
+ assert . equal ( sortedKeys [ 0 ] , jsonTwo . key ) ;
125
+ assert . equal ( sortedKeys [ 1 ] , jsonOne . key ) ;
126
+ } ) ;
127
+
79
128
it ( 'testSortTopItemsTitle' , async function ( ) {
80
129
let response = await API . userGet (
81
130
config . userID ,
0 commit comments