Commit 1bd1918a authored by Daisuke Akatsuka's avatar Daisuke Akatsuka
Browse files

Bug 1834646: Adapt to new addon suggestions format in RemoteSettings r=adw

parent 995fadce
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -165,14 +165,27 @@ export class AddonSuggestions extends BaseFeature {
  }

  async onRemoteSettingsSync(rs) {
    const records = await rs.get({ filters: { type: "amo_suggestion" } });
    const records = await rs.get({ filters: { type: "amo-suggestions" } });
    if (rs != lazy.QuickSuggestRemoteSettings.rs) {
      return;
    }

    const suggestions = records.map(r => r.amo_suggestion);
    this.#suggestionsMap = new lazy.SuggestionsMap();
    this.#suggestionsMap.add(suggestions);
    const suggestionsMap = new lazy.SuggestionsMap();

    for (const record of records) {
      const { buffer } = await rs.attachments.download(record);
      if (rs != lazy.QuickSuggestRemoteSettings.rs) {
        return;
      }

      const results = JSON.parse(new TextDecoder("utf-8").decode(buffer));
      await suggestionsMap.add(results);
      if (rs != lazy.QuickSuggestRemoteSettings.rs) {
        return;
      }
    }

    this.#suggestionsMap = suggestionsMap;
  }

  async makeResult(queryContext, suggestion, searchString) {
+41 −54
Original line number Diff line number Diff line
@@ -37,9 +37,9 @@ const MERINO_SUGGESTIONS = [

const REMOTE_SETTINGS_RESULTS = [
  {
    type: "amo_suggestion",
    schema: 1,
    amo_suggestion: {
    type: "amo-suggestions",
    attachment: [
      {
        url: "https://example.com/first-addon",
        guid: "first@addon",
        icon: "https://example.com/first-addon.svg",
@@ -50,13 +50,7 @@ const REMOTE_SETTINGS_RESULTS = [
        number_of_ratings: 1256,
        is_top_pick: true,
      },
    id: "amo_suggestion_1",
    last_modified: 1,
  },
      {
    type: "amo_suggestion",
    schema: 1,
    amo_suggestion: {
        url: "https://example.com/second-addon",
        guid: "second@addon",
        icon: "https://example.com/second-addon.svg",
@@ -67,13 +61,7 @@ const REMOTE_SETTINGS_RESULTS = [
        number_of_ratings: 256,
        is_top_pick: false,
      },
    id: "amo_suggestion_2",
    last_modified: 1,
  },
      {
    type: "amo_suggestion",
    schema: 1,
    amo_suggestion: {
        url: "https://example.com/third-addon",
        guid: "third@addon",
        icon: "https://example.com/third-addon.svg",
@@ -83,8 +71,7 @@ const REMOTE_SETTINGS_RESULTS = [
        description: "Description for the Third Addon",
        number_of_ratings: 3,
      },
    id: "amo_suggestion_3",
    last_modified: 1,
    ],
  },
];

@@ -267,42 +254,42 @@ add_task(async function remoteSettings() {
    {
      input: "first",
      expected: makeExpectedResult({
        suggestion: REMOTE_SETTINGS_RESULTS[0].amo_suggestion,
        suggestion: REMOTE_SETTINGS_RESULTS[0].attachment[0],
        source: "remote-settings",
      }),
    },
    {
      input: "1st",
      expected: makeExpectedResult({
        suggestion: REMOTE_SETTINGS_RESULTS[0].amo_suggestion,
        suggestion: REMOTE_SETTINGS_RESULTS[0].attachment[0],
        source: "remote-settings",
      }),
    },
    {
      input: "second",
      expected: makeExpectedResult({
        suggestion: REMOTE_SETTINGS_RESULTS[1].amo_suggestion,
        suggestion: REMOTE_SETTINGS_RESULTS[0].attachment[1],
        source: "remote-settings",
      }),
    },
    {
      input: "2nd",
      expected: makeExpectedResult({
        suggestion: REMOTE_SETTINGS_RESULTS[1].amo_suggestion,
        suggestion: REMOTE_SETTINGS_RESULTS[0].attachment[1],
        source: "remote-settings",
      }),
    },
    {
      input: "third",
      expected: makeExpectedResult({
        suggestion: REMOTE_SETTINGS_RESULTS[2].amo_suggestion,
        suggestion: REMOTE_SETTINGS_RESULTS[0].attachment[2],
        source: "remote-settings",
      }),
    },
    {
      input: "3rd",
      expected: makeExpectedResult({
        suggestion: REMOTE_SETTINGS_RESULTS[2].amo_suggestion,
        suggestion: REMOTE_SETTINGS_RESULTS[0].attachment[2],
        source: "remote-settings",
      }),
    },