import { assertEquals } from 'std/assert';
import { createClient } from '@supabase/supabase-js';
import {
  assertSpyCall,
  assertSpyCalls,
  returnsNext,
  stub,
} from 'std/testing/mock';

import { ISource } from '../models/source.ts';
import { IProfile } from '../models/profile.ts';
import { getNitterFeed, parseNitterOptions } from './nitter.ts';
import { utils } from '../utils/index.ts';
import { feedutils } from './utils/index.ts';

const supabaseClient = createClient('http://localhost:54321', 'test123');
const mockProfile: IProfile = {
  id: '',
  tier: 'free',
  createdAt: 0,
  updatedAt: 0,
};
const mockSource: ISource = {
  id: '',
  columnId: 'mycolumn',
  userId: 'myuser',
  type: 'medium',
  title: '',
};

const responseTag = `<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
   <channel>
      <atom:link href="http://nitter.feeddeck.app/search" rel="self" type="application/rss+xml" />
      <title>Search results for "kubernetes"</title>
      <link>http://nitter.feeddeck.app/search</link>
      <description>Twitter feed for: Search "kubernetes". Generated by nitter.feeddeck.app</description>
      <language>en-us</language>
      <ttl>40</ttl>
      <item>
         <title>RT by @lunacyyan: Kubernetes V1.27 : Safeguarding Pod with MemoryThrottlingFactor

Read more: https://faun.pub/kubernetes-v1-27-safeguarding-pod-with-memorythrottlingfactor-cfbccde10de</title>
         <dc:creator>@CloudIslamabad</dc:creator>
         <description><![CDATA[<p>Kubernetes V1.27 : Safeguarding Pod with MemoryThrottlingFactor<br>
<br>
Read more: <a href="https://faun.pub/kubernetes-v1-27-safeguarding-pod-with-memorythrottlingfactor-cfbccde10de">faun.pub/kubernetes-v1-27-sa…</a></p>]]></description>
         <pubDate>Sat, 09 Dec 2023 17:42:53 GMT</pubDate>
         <guid>http://nitter.feeddeck.app/CloudIslamabad/status/1733542748857483570#m</guid>
         <link>http://nitter.feeddeck.app/CloudIslamabad/status/1733542748857483570#m</link>
      </item>
      <item>
         <title>RT by @mochizuki875: お疲れ様です！
明日はCNDT2023のCommunity LTにて、16:10からKubernetes Meetup Noviceが登壇させて頂きます！

ぜひ遊びに来ていただけると嬉しいです！！
よろしくお願いいたします！
https://event.cloudnativedays.jp/cndt2023/community_lt

#k8snovice #CNDT2023</title>
         <dc:creator>@URyo_0213</dc:creator>
         <description><![CDATA[<p>お疲れ様です！<br>
明日はCNDT2023のCommunity LTにて、16:10からKubernetes Meetup Noviceが登壇させて頂きます！<br>
<br>
ぜひ遊びに来ていただけると嬉しいです！！<br>
よろしくお願いいたします！<br>
<a href="https://event.cloudnativedays.jp/cndt2023/community_lt">event.cloudnativedays.jp/cnd…</a><br>
<br>
<a href="http://nitter.feeddeck.app/search?q=%23k8snovice">#k8snovice</a> <a href="http://nitter.feeddeck.app/search?q=%23CNDT2023">#CNDT2023</a></p>]]></description>
         <pubDate>Sun, 10 Dec 2023 11:22:30 GMT</pubDate>
         <guid>http://nitter.feeddeck.app/URyo_0213/status/1733809409393099181#m</guid>
         <link>http://nitter.feeddeck.app/URyo_0213/status/1733809409393099181#m</link>
      </item>
      <item>
         <title>Did you pass the Kubernetes certified application developer (CKAD) exam on your first attempt?

#Kubernetes #devops #cka</title>
         <dc:creator>@AbdelVA</dc:creator>
         <description><![CDATA[<p>Did you pass the Kubernetes certified application developer (CKAD) exam on your first attempt?<br>
<br>
<a href="http://nitter.feeddeck.app/search?q=%23Kubernetes">#Kubernetes</a> <a href="http://nitter.feeddeck.app/search?q=%23devops">#devops</a> <a href="http://nitter.feeddeck.app/search?q=%23cka">#cka</a></p>]]></description>
         <pubDate>Sun, 10 Dec 2023 11:42:45 GMT</pubDate>
         <guid>http://nitter.feeddeck.app/AbdelVA/status/1733814503551197653#m</guid>
         <link>http://nitter.feeddeck.app/AbdelVA/status/1733814503551197653#m</link>
      </item>
      <item>
         <title>RT by @eliyyov: Your app,
in a container,
in a pod,
in Kubernetes,
as a YAML file
with Helm Charts
deployed with ArgoCD</title>
         <dc:creator>@memenetes</dc:creator>
         <description><![CDATA[<p>Your app,<br>
in a container,<br>
in a pod,<br>
in Kubernetes,<br>
as a YAML file<br>
with Helm Charts<br>
deployed with ArgoCD</p>
<img src="http://nitter.feeddeck.app/pic/ext_tw_video_thumb%2F1730270796612788224%2Fpu%2Fimg%2Fn2of8rx2u0oXtVAw.jpg" style="max-width:250px;" />]]></description>
         <pubDate>Thu, 30 Nov 2023 17:01:23 GMT</pubDate>
         <guid>http://nitter.feeddeck.app/memenetes/status/1730270811548701061#m</guid>
         <link>http://nitter.feeddeck.app/memenetes/status/1730270811548701061#m</link>
      </item>
   </channel>
</rss>`;

const responseUser = `<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
   <channel>
      <atom:link href="http://nitter.feeddeck.app/rico_berger/rss" rel="self" type="application/rss+xml" />
      <title>Rico Berger / @rico_berger</title>
      <link>http://nitter.feeddeck.app/rico_berger</link>
      <description>Twitter feed for: @rico_berger. Generated by nitter.feeddeck.app</description>
      <language>en-us</language>
      <ttl>40</ttl>
      <image>
         <title>Rico Berger / @rico_berger</title>
         <link>http://nitter.feeddeck.app/rico_berger</link>
         <url>http://nitter.feeddeck.app/pic/pbs.twimg.com%2Fprofile_images%2F1076066289511206912%2Fi8mug5EL_400x400.jpg</url>
         <width>128</width>
         <height>128</height>
      </image>
      <item>
         <title>RT by @rico_berger: Blog: Gateway API v1.0: GA Release - https://kubernetes.io/blog/2023/10/31/gateway-api-ga/ #Kubernetes</title>
         <dc:creator>@K8sContributors</dc:creator>
         <description><![CDATA[<p>Blog: Gateway API v1.0: GA Release - <a href="https://kubernetes.io/blog/2023/10/31/gateway-api-ga/">kubernetes.io/blog/2023/10/3…</a> <a href="http://nitter.feeddeck.app/search?q=%23Kubernetes">#Kubernetes</a></p>
<img src="http://nitter.feeddeck.app/pic/card_img%2F1729729773448970240%2F7PcfwkrY%3Fformat%3Dpng%26name%3D420x420_2" style="max-width:250px;" />]]></description>
         <pubDate>Tue, 31 Oct 2023 18:42:00 GMT</pubDate>
         <guid>http://nitter.feeddeck.app/K8sContributors/status/1719424500591210559#m</guid>
         <link>http://nitter.feeddeck.app/K8sContributors/status/1719424500591210559#m</link>
      </item>
      <item>
         <title>RT by @rico_berger: We are excited to announce the launch of OpenTofu, an open source alternative to Terraform's widely used infrastructure as code provisioning tool.

Read the announcement:
https://hubs.la/Q022JfPQ0
#opensource #opentofu #ossummit</title>
         <dc:creator>@linuxfoundation</dc:creator>
         <description><![CDATA[<p>We are excited to announce the launch of OpenTofu, an open source alternative to Terraform's widely used infrastructure as code provisioning tool.<br>
<br>
Read the announcement:<br>
<a href="https://hubs.la/Q022JfPQ0">hubs.la/Q022JfPQ0</a><br>
<a href="http://nitter.feeddeck.app/search?q=%23opensource">#opensource</a> <a href="http://nitter.feeddeck.app/search?q=%23opentofu">#opentofu</a> <a href="http://nitter.feeddeck.app/search?q=%23ossummit">#ossummit</a></p>
<img src="http://nitter.feeddeck.app/pic/media%2FF6c1nOIWIAAOSAy.jpg" style="max-width:250px;" />]]></description>
         <pubDate>Wed, 20 Sep 2023 07:00:00 GMT</pubDate>
         <guid>http://nitter.feeddeck.app/linuxfoundation/status/1704389933526299129#m</guid>
         <link>http://nitter.feeddeck.app/linuxfoundation/status/1704389933526299129#m</link>
      </item>
      <item>
         <title>RT by @rico_berger: &#x1f389;&#x1f389;&#x1f389; kubenav v4 is finally available and can be downloaded from the Apple App Store (https://apps.apple.com/us/app/kubenav/id1494512160) or Google Play (https://play.google.com/store/apps/details?id=io.kubenav.kubenav) &#x1f973;&#x1f973;&#x1f973; #Kubernetes</title>
         <dc:creator>@kubenav</dc:creator>
         <description><![CDATA[<p>🎉🎉🎉 kubenav v4 is finally available and can be downloaded from the Apple App Store (<a href="https://apps.apple.com/us/app/kubenav/id1494512160">apps.apple.com/us/app/kubena…</a>) or Google Play (<a href="https://play.google.com/store/apps/details?id=io.kubenav.kubenav">play.google.com/store/apps/d…</a>) 🥳🥳🥳 <a href="http://nitter.feeddeck.app/search?q=%23Kubernetes">#Kubernetes</a></p>
<img src="http://nitter.feeddeck.app/pic/media%2FFnVbCgSXEBAg-am.jpg" style="max-width:250px;" />
<img src="http://nitter.feeddeck.app/pic/media%2FFnVbCgOXEAk3St9.jpg" style="max-width:250px;" />
<img src="http://nitter.feeddeck.app/pic/media%2FFnVbCgOXEAYOZFK.jpg" style="max-width:250px;" />
<img src="http://nitter.feeddeck.app/pic/media%2FFnVbH9hXEAEsd4I.jpg" style="max-width:250px;" />]]></description>
         <pubDate>Wed, 25 Jan 2023 17:29:00 GMT</pubDate>
         <guid>http://nitter.feeddeck.app/kubenav/status/1618299915129720832#m</guid>
         <link>http://nitter.feeddeck.app/kubenav/status/1618299915129720832#m</link>
      </item>
   </channel>
</rss>`;

Deno.test('parseNitterOptions', () => {
  assertEquals(
    parseNitterOptions('https://nitter.net/rico_berger/rss'),
    {
      feedUrl: 'https://nitter.net/rico_berger/rss',
      sourceTitle: '@rico_berger',
      isUsername: true,
      isCustomInstance: true,
    },
  );
  assertEquals(
    parseNitterOptions('https://nitter.net/search/rss?f=tweets&q=kubernetes'),
    {
      feedUrl: 'https://nitter.net/search/rss?f=tweets&q=kubernetes',
      sourceTitle: 'kubernetes',
      isUsername: false,
      isCustomInstance: true,
    },
  );
  assertEquals(
    parseNitterOptions('@rico_berger'),
    {
      feedUrl: '/rico_berger/rss',
      sourceTitle: '@rico_berger',
      isUsername: true,
      isCustomInstance: false,
    },
  );
  assertEquals(
    parseNitterOptions('kubernetes'),
    {
      feedUrl: '/search/rss?f=tweets&q=kubernetes',
      sourceTitle: 'kubernetes',
      isUsername: false,
      isCustomInstance: false,
    },
  );
});

Deno.test('getNitterFeed - Tag', async () => {
  const fetchWithTimeoutSpy = stub(
    utils,
    'fetchWithTimeout',
    returnsNext([
      new Promise((resolve) => {
        resolve(new Response(responseTag, { status: 200 }));
      }),
    ]),
  );

  try {
    const { source, items } = await getNitterFeed(
      supabaseClient,
      undefined,
      mockProfile,
      {
        ...mockSource,
        options: {
          nitter: 'https://nitter.net/search/rss?f=tweets&q=kubernetes',
        },
      },
      undefined,
    );
    feedutils.assertEqualsSource(source, {
      'id': 'nitter-myuser-mycolumn-14a83e961dc175e20f36e70373cbae6e',
      'columnId': 'mycolumn',
      'userId': 'myuser',
      'type': 'nitter',
      'title': 'kubernetes',
      'options': {
        'nitter': 'https://nitter.net/search/rss?f=tweets&q=kubernetes',
      },
      'link': 'http://nitter.feeddeck.app/search',
    });
    feedutils.assertEqualsItems(items, [{
      'id':
        'nitter-myuser-mycolumn-14a83e961dc175e20f36e70373cbae6e-e15978ba81b685189dfb89c07aa969db',
      'userId': 'myuser',
      'columnId': 'mycolumn',
      'sourceId': 'nitter-myuser-mycolumn-14a83e961dc175e20f36e70373cbae6e',
      'title':
        'RT by @lunacyyan: Kubernetes V1.27 : Safeguarding Pod with MemoryThrottlingFactor\n\nRead more: https://faun.pub/kubernetes-v1-27-safeguarding-pod-with-memorythrottlingfactor-cfbccde10de',
      'link':
        'http://nitter.feeddeck.app/CloudIslamabad/status/1733542748857483570#m',
      'description':
        '<p>Kubernetes V1.27 : Safeguarding Pod with MemoryThrottlingFactor<br>\n<br>\nRead more: <a href="https://faun.pub/kubernetes-v1-27-safeguarding-pod-with-memorythrottlingfactor-cfbccde10de">faun.pub/kubernetes-v1-27-sa…</a></p>',
      'author': '@CloudIslamabad',
      'publishedAt': 1702143773,
    }, {
      'id':
        'nitter-myuser-mycolumn-14a83e961dc175e20f36e70373cbae6e-34df7ecc085e3e91133b6912c0775e03',
      'userId': 'myuser',
      'columnId': 'mycolumn',
      'sourceId': 'nitter-myuser-mycolumn-14a83e961dc175e20f36e70373cbae6e',
      'title':
        'RT by @mochizuki875: お疲れ様です！\n明日はCNDT2023のCommunity LTにて、16:10からKubernetes Meetup Noviceが登壇させて頂きます！\n\nぜひ遊びに来ていただけると嬉しいです！！\nよろしくお願いいたします！\nhttps://event.cloudnativedays.jp/cndt2023/community_lt\n\n#k8snovice #CNDT2023',
      'link':
        'http://nitter.feeddeck.app/URyo_0213/status/1733809409393099181#m',
      'description':
        '<p>お疲れ様です！<br>\n明日はCNDT2023のCommunity LTにて、16:10からKubernetes Meetup Noviceが登壇させて頂きます！<br>\n<br>\nぜひ遊びに来ていただけると嬉しいです！！<br>\nよろしくお願いいたします！<br>\n<a href="https://event.cloudnativedays.jp/cndt2023/community_lt">event.cloudnativedays.jp/cnd…</a><br>\n<br>\n<a href="http://nitter.feeddeck.app/search?q=%23k8snovice">#k8snovice</a> <a href="http://nitter.feeddeck.app/search?q=%23CNDT2023">#CNDT2023</a></p>',
      'author': '@URyo_0213',
      'publishedAt': 1702207350,
    }, {
      'id':
        'nitter-myuser-mycolumn-14a83e961dc175e20f36e70373cbae6e-475ee6bb2ed19e551d0547545ba4e5a0',
      'userId': 'myuser',
      'columnId': 'mycolumn',
      'sourceId': 'nitter-myuser-mycolumn-14a83e961dc175e20f36e70373cbae6e',
      'title':
        'Did you pass the Kubernetes certified application developer (CKAD) exam on your first attempt?\n\n#Kubernetes #devops #cka',
      'link': 'http://nitter.feeddeck.app/AbdelVA/status/1733814503551197653#m',
      'description':
        '<p>Did you pass the Kubernetes certified application developer (CKAD) exam on your first attempt?<br>\n<br>\n<a href="http://nitter.feeddeck.app/search?q=%23Kubernetes">#Kubernetes</a> <a href="http://nitter.feeddeck.app/search?q=%23devops">#devops</a> <a href="http://nitter.feeddeck.app/search?q=%23cka">#cka</a></p>',
      'author': '@AbdelVA',
      'publishedAt': 1702208565,
    }, {
      'id':
        'nitter-myuser-mycolumn-14a83e961dc175e20f36e70373cbae6e-d07f5752845c01a8288c393109770f3c',
      'userId': 'myuser',
      'columnId': 'mycolumn',
      'sourceId': 'nitter-myuser-mycolumn-14a83e961dc175e20f36e70373cbae6e',
      'title':
        'RT by @eliyyov: Your app,\nin a container,\nin a pod,\nin Kubernetes,\nas a YAML file\nwith Helm Charts\ndeployed with ArgoCD',
      'link':
        'http://nitter.feeddeck.app/memenetes/status/1730270811548701061#m',
      'options': {
        'media': [
          'https://nitter.feeddeck.app/pic/ext_tw_video_thumb%2F1730270796612788224%2Fpu%2Fimg%2Fn2of8rx2u0oXtVAw.jpg',
        ],
      },
      'description':
        '<p>Your app,<br>\nin a container,<br>\nin a pod,<br>\nin Kubernetes,<br>\nas a YAML file<br>\nwith Helm Charts<br>\ndeployed with ArgoCD</p>\n<img src="http://nitter.feeddeck.app/pic/ext_tw_video_thumb%2F1730270796612788224%2Fpu%2Fimg%2Fn2of8rx2u0oXtVAw.jpg" style="max-width:250px;" />',
      'author': '@memenetes',
      'publishedAt': 1701363683,
    }]);
  } finally {
    fetchWithTimeoutSpy.restore();
  }

  assertSpyCall(fetchWithTimeoutSpy, 0, {
    args: ['https://nitter.net/search/rss?f=tweets&q=kubernetes', {
      method: 'get',
    }, 5000],
    returned: new Promise((resolve) => {
      resolve(new Response(responseTag, { status: 200 }));
    }),
  });
  assertSpyCalls(fetchWithTimeoutSpy, 1);
});

Deno.test('getNitterFeed - User', async () => {
  const fetchWithTimeoutSpy = stub(
    utils,
    'fetchWithTimeout',
    returnsNext([
      new Promise((resolve) => {
        resolve(new Response(responseUser, { status: 200 }));
      }),
    ]),
  );
  const uploadSourceIconSpy = stub(
    feedutils,
    'uploadSourceIcon',
    returnsNext([
      new Promise((resolve) => {
        resolve(
          'https://media.hachyderm.io/accounts/avatars/109/773/619/675/865/785/original/bf731ded4166a661.png',
        );
      }),
    ]),
  );

  try {
    const { source, items } = await getNitterFeed(
      supabaseClient,
      undefined,
      mockProfile,
      {
        ...mockSource,
        options: { nitter: 'https://nitter.net/rico_berger/rss' },
      },
      undefined,
    );
    feedutils.assertEqualsSource(source, {
      'id': 'nitter-myuser-mycolumn-2f69b5c79645e7868dbefdee825bbb90',
      'columnId': 'mycolumn',
      'userId': 'myuser',
      'type': 'nitter',
      'title': '@rico_berger',
      'options': { 'nitter': 'https://nitter.net/rico_berger/rss' },
      'link': 'http://nitter.feeddeck.app/rico_berger',
      'icon':
        'https://media.hachyderm.io/accounts/avatars/109/773/619/675/865/785/original/bf731ded4166a661.png',
    });
    feedutils.assertEqualsItems(items, [{
      'id':
        'nitter-myuser-mycolumn-2f69b5c79645e7868dbefdee825bbb90-ed3ded7ee38f30e9c7e5e9f181ed96c2',
      'userId': 'myuser',
      'columnId': 'mycolumn',
      'sourceId': 'nitter-myuser-mycolumn-2f69b5c79645e7868dbefdee825bbb90',
      'title':
        'RT by @rico_berger: Blog: Gateway API v1.0: GA Release - https://kubernetes.io/blog/2023/10/31/gateway-api-ga/ #Kubernetes',
      'link':
        'http://nitter.feeddeck.app/K8sContributors/status/1719424500591210559#m',
      'options': {
        'media': [
          'https://nitter.feeddeck.app/pic/card_img%2F1729729773448970240%2F7PcfwkrY%3Fformat%3Dpng%26name%3D420x420_2',
        ],
      },
      'description':
        '<p>Blog: Gateway API v1.0: GA Release - <a href="https://kubernetes.io/blog/2023/10/31/gateway-api-ga/">kubernetes.io/blog/2023/10/3…</a> <a href="http://nitter.feeddeck.app/search?q=%23Kubernetes">#Kubernetes</a></p>\n<img src="http://nitter.feeddeck.app/pic/card_img%2F1729729773448970240%2F7PcfwkrY%3Fformat%3Dpng%26name%3D420x420_2" style="max-width:250px;" />',
      'author': '@K8sContributors',
      'publishedAt': 1698777720,
    }, {
      'id':
        'nitter-myuser-mycolumn-2f69b5c79645e7868dbefdee825bbb90-d185c4fa2b5b22eb0ea0cfd5de56802a',
      'userId': 'myuser',
      'columnId': 'mycolumn',
      'sourceId': 'nitter-myuser-mycolumn-2f69b5c79645e7868dbefdee825bbb90',
      'title':
        'RT by @rico_berger: We are excited to announce the launch of OpenTofu, an open source alternative to Terraform\'s widely used infrastructure as code provisioning tool.\n\nRead the announcement:\nhttps://hubs.la/Q022JfPQ0\n#opensource #opentofu #ossummit',
      'link':
        'http://nitter.feeddeck.app/linuxfoundation/status/1704389933526299129#m',
      'options': {
        'media': [
          'https://nitter.feeddeck.app/pic/media%2FF6c1nOIWIAAOSAy.jpg',
        ],
      },
      'description':
        '<p>We are excited to announce the launch of OpenTofu, an open source alternative to Terraform\'s widely used infrastructure as code provisioning tool.<br>\n<br>\nRead the announcement:<br>\n<a href="https://hubs.la/Q022JfPQ0">hubs.la/Q022JfPQ0</a><br>\n<a href="http://nitter.feeddeck.app/search?q=%23opensource">#opensource</a> <a href="http://nitter.feeddeck.app/search?q=%23opentofu">#opentofu</a> <a href="http://nitter.feeddeck.app/search?q=%23ossummit">#ossummit</a></p>\n<img src="http://nitter.feeddeck.app/pic/media%2FF6c1nOIWIAAOSAy.jpg" style="max-width:250px;" />',
      'author': '@linuxfoundation',
      'publishedAt': 1695193200,
    }, {
      'id':
        'nitter-myuser-mycolumn-2f69b5c79645e7868dbefdee825bbb90-708a757b055af5aa824ef6c361a4f30c',
      'userId': 'myuser',
      'columnId': 'mycolumn',
      'sourceId': 'nitter-myuser-mycolumn-2f69b5c79645e7868dbefdee825bbb90',
      'title':
        'RT by @rico_berger: 🎉🎉🎉 kubenav v4 is finally available and can be downloaded from the Apple App Store (https://apps.apple.com/us/app/kubenav/id1494512160) or Google Play (https://play.google.com/store/apps/details?id=io.kubenav.kubenav) 🥳🥳🥳 #Kubernetes',
      'link': 'http://nitter.feeddeck.app/kubenav/status/1618299915129720832#m',
      'options': {
        'media': [
          'https://nitter.feeddeck.app/pic/media%2FFnVbCgSXEBAg-am.jpg',
          'https://nitter.feeddeck.app/pic/media%2FFnVbCgOXEAk3St9.jpg',
          'https://nitter.feeddeck.app/pic/media%2FFnVbCgOXEAYOZFK.jpg',
          'https://nitter.feeddeck.app/pic/media%2FFnVbH9hXEAEsd4I.jpg',
        ],
      },
      'description':
        '<p>🎉🎉🎉 kubenav v4 is finally available and can be downloaded from the Apple App Store (<a href="https://apps.apple.com/us/app/kubenav/id1494512160">apps.apple.com/us/app/kubena…</a>) or Google Play (<a href="https://play.google.com/store/apps/details?id=io.kubenav.kubenav">play.google.com/store/apps/d…</a>) 🥳🥳🥳 <a href="http://nitter.feeddeck.app/search?q=%23Kubernetes">#Kubernetes</a></p>\n<img src="http://nitter.feeddeck.app/pic/media%2FFnVbCgSXEBAg-am.jpg" style="max-width:250px;" />\n<img src="http://nitter.feeddeck.app/pic/media%2FFnVbCgOXEAk3St9.jpg" style="max-width:250px;" />\n<img src="http://nitter.feeddeck.app/pic/media%2FFnVbCgOXEAYOZFK.jpg" style="max-width:250px;" />\n<img src="http://nitter.feeddeck.app/pic/media%2FFnVbH9hXEAEsd4I.jpg" style="max-width:250px;" />',
      'author': '@kubenav',
      'publishedAt': 1674667740,
    }]);
  } finally {
    fetchWithTimeoutSpy.restore();
    uploadSourceIconSpy.restore();
  }

  assertSpyCall(fetchWithTimeoutSpy, 0, {
    args: ['https://nitter.net/rico_berger/rss', {
      method: 'get',
    }, 5000],
    returned: new Promise((resolve) => {
      resolve(new Response(responseUser, { status: 200 }));
    }),
  });
  assertSpyCall(uploadSourceIconSpy, 0, {
    args: [
      supabaseClient,
      {
        'id': 'nitter-myuser-mycolumn-2f69b5c79645e7868dbefdee825bbb90',
        'columnId': 'mycolumn',
        'userId': 'myuser',
        'type': 'nitter',
        'title': '@rico_berger',
        'options': { 'nitter': 'https://nitter.net/rico_berger/rss' },
        'link': 'http://nitter.feeddeck.app/rico_berger',
        'icon':
          'https://media.hachyderm.io/accounts/avatars/109/773/619/675/865/785/original/bf731ded4166a661.png',
      },
    ],
    returned: new Promise((resolve) => {
      resolve(
        'https://media.hachyderm.io/accounts/avatars/109/773/619/675/865/785/original/bf731ded4166a661.png',
      );
    }),
  });
  assertSpyCalls(fetchWithTimeoutSpy, 1);
  assertSpyCalls(uploadSourceIconSpy, 1);
});
