summaryrefslogtreecommitdiffstats
path: root/services/sync/tests/unit/test_addons_validator.js
blob: 069f15ef3b6be007435ef08a24c0ab8bd0f4085b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

const { AddonValidator } = ChromeUtils.import(
  "resource://services-sync/engines/addons.js"
);

function getDummyServerAndClient() {
  return {
    server: [
      {
        id: "1111",
        applicationID: Services.appinfo.ID,
        addonID: "synced-addon@example.com",
        enabled: true,
        source: "amo",
        understood: true,
      },
    ],
    client: [
      {
        syncGUID: "1111",
        id: "synced-addon@example.com",
        type: "extension",
        isSystem: false,
        isSyncable: true,
      },
      {
        syncGUID: "2222",
        id: "system-addon@example.com",
        type: "extension",
        isSystem: true,
        isSyncable: false,
      },
      {
        // Plugins don't have a `syncedGUID`, but we don't sync them, so we
        // shouldn't report them as client duplicates.
        id: "some-plugin",
        type: "plugin",
      },
      {
        id: "another-plugin",
        type: "plugin",
      },
    ],
  };
}

add_task(async function test_valid() {
  let { server, client } = getDummyServerAndClient();
  let validator = new AddonValidator({
    _findDupe(item) {
      return null;
    },
    isAddonSyncable(item) {
      return item.type != "plugin";
    },
  });
  let {
    problemData,
    clientRecords,
    records,
    deletedRecords,
  } = await validator.compareClientWithServer(client, server);
  equal(clientRecords.length, 4);
  equal(records.length, 1);
  equal(deletedRecords.length, 0);
  deepEqual(problemData, validator.emptyProblemData());
});