Skip to content

Commit

Permalink
?sort=editBy for group libraries
Browse files Browse the repository at this point in the history
test for zotero#154
  • Loading branch information
abaevbog committed Jun 23, 2023
1 parent d8f3427 commit 2e7a853
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion tests/remote_js/test/3/sortTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const assert = chai.assert;
var config = require('config');
const API = require('../../api3.js');
const Helpers = require('../../helpers3.js');
const { API3Before, API3After } = require("../shared.js");
const { API3Before, API3After, resetGroups } = require("../shared.js");

describe('SortTests', function () {
this.timeout(config.timeout);
Expand All @@ -21,6 +21,7 @@ describe('SortTests', function () {
before(async function () {
await API3Before();
await setup();
await resetGroups();
});

after(async function () {
Expand Down Expand Up @@ -76,6 +77,54 @@ describe('SortTests', function () {
}*/
};

it('test_sort_group_by_editedBy', async function () {
// user 1 makes item
let jsonOne = await API.groupCreateItem(
config.ownedPrivateGroupID,
'book',
{ title: `title_one` },
true,
'jsonData'
);

API.useAPIKey(config.user2APIKey);

// user 2 makes item
let jsonTwo = await API.groupCreateItem(
config.ownedPrivateGroupID,
'book',
{ title: `title_two` },
true,
'jsonData'
);

// make sure, user's one item goes first
let response = await API.get(`groups/${config.ownedPrivateGroupID}/items?sort=editedBy&format=keys`);
let sortedKeys = response.data.split('\n');
assert.equal(sortedKeys[0], jsonOne.key);
assert.equal(sortedKeys[1], jsonTwo.key);

// user 2 updates user1's item, and the other way around
response = await API.patch(`groups/${config.ownedPrivateGroupID}/items/${jsonOne.key}`,
JSON.stringify({ title: 'updated_by_user 2' }),
{ 'If-Unmodified-Since-Version': jsonOne.version });

Helpers.assert204(response);

API.useAPIKey(config.apiKey);

response = await API.patch(`groups/${config.ownedPrivateGroupID}/items/${jsonTwo.key}`,
JSON.stringify({ title: 'updated_by_user 2' }),
{ 'If-Unmodified-Since-Version': jsonTwo.version });
Helpers.assert204(response);

// now order should be switched
response = await API.get(`groups/${config.ownedPrivateGroupID}/items?sort=editedBy&format=keys`);
sortedKeys = response.data.split('\n');
assert.equal(sortedKeys[0], jsonTwo.key);
assert.equal(sortedKeys[1], jsonOne.key);
});

it('testSortTopItemsTitle', async function () {
let response = await API.userGet(
config.userID,
Expand Down

0 comments on commit 2e7a853

Please sign in to comment.