package bard

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

const respText = `[["wrb.fr",null,"[null,[\"c_5d1d4a9e973bc35a\",\"r_5d1d4a9e973bc013\"],[[\"latest news from hackernews\",1],[\"Why do people use Hacker News?\",4],[\"Is the hacker news legit?\",4]],null,[[\"rc_5d1d4a9e973bcfb0\",[\"Sure, here are some of the latest news from Hacker News on September 9, 2023:\\n\\n* **NSO group iPhone zero-click, zero-day exploit captured in the wild.** Citizen Lab, a research group at the University of Toronto, has released details of a zero-click exploit developed by the NSO Group that can be used to remotely take control of iPhones without the need for any user interaction. The exploit is believed to have been used by the NSO Group to target journalists, activists, and government officials.\\n* **Chrome now tracks users and shares a “topic” list with advertisers.** Google has updated its Chrome browser to include a new feature that tracks users' browsing activity and shares it with advertisers. The feature, called Topics, is designed to replace the previous Interest-based advertising feature. However, critics have argued that Topics is still a form of tracking and that it could be used to build detailed profiles of users.\\n* **UK pulls back from clash with Big Tech over private messaging.** The UK government has announced that it will not be pursuing legislation that would have forced tech companies to break encryption in order to facilitate government surveillance. The decision was met with relief by privacy advocates, who had warned that the legislation would have had a chilling effect on free speech.\\n* **Internet-connected cars fail privacy and security tests conducted by Mozilla.** Mozilla has published the results of a study that found that many internet-connected cars are vulnerable to privacy and security attacks. The study found that many cars collect and transmit personal data without users' knowledge or consent, and that they are often vulnerable to hacking attacks.\\n* **North Korean campaign targeting security researchers.** Google has warned that a North Korean hacking group is targeting security researchers with phishing emails. The emails are designed to trick researchers into clicking on malicious links or opening attachments that contain malware.\\n\\nThese are just a few of the latest news from Hacker News. For more news, you can visit the website or follow Hacker News on social media.\"],[],null,null,null,true,null,null,\"en\",null,null,[null,null,null,null,null,[[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,[null,null,null,null,null,null,true],null,null,null,1]],null,null,null,null,null,null,null,null,null,null,null,null,null,[[]]],null,false,true,true,null,null,false],[\"rc_5d1d4a9e973bcc69\",[\"Sure, here are some of the latest news from Hacker News on September 9, 2023:\\n\\n* **NSO group iPhone zero-click, zero-day exploit captured in the wild.** Citizen Lab researchers have found evidence of a zero-click, zero-day exploit for iPhones that was developed by the NSO Group, an Israeli cyberarms firm. The exploit allows attackers to remotely take control of an iPhone without the user needing to click on a malicious link or open a malicious attachment.\\n* **Chrome now tracks users and shares a “topic” list with advertisers.** Google has announced that Chrome will now track users and share a “topic” list with advertisers. The topic list is a collection of topics that Chrome believes are relevant to the user, based on their browsing history. Advertisers can then use this information to show more relevant ads to users.\\n* **Bun v1.0.0.** Bun is a new file sharing app that is designed to be more private and secure than traditional file sharing apps. Bun uses end-to-end encryption to protect files from being intercepted by third parties.\\n* **UK pulls back from clash with Big Tech over private messaging.** The UK government has announced that it will not be pursuing legislation that would have forced tech companies to break encryption in private messaging apps. The government said that it had listened to the concerns of privacy advocates and that it would not be in the best interests of the public to weaken encryption.\\n* **Touch Pianist.** Touch Pianist is a new website that allows users to learn how to play the piano by touch. The website uses artificial intelligence to track the user's fingers and provide feedback on their playing.\\n\\nThese are just a few of the latest news from Hacker News. For more news, you can visit the Hacker News website or follow them on social media.\"],[],null,null,null,true,null,null,\"en\",null,null,[null,null,null,null,null,[[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,[null,null,null,null,null,null,true],null,null,null,1]],null,null,null,null,null,null,null,null,null,null,null,null,null,[[]]],null,false,true,true,null,null,false],[\"rc_5d1d4a9e973bc922\",[\"Sure, here are some of the latest news from Hacker News as of September 9, 2023, 18:51 PST:\\n\\n* **NSO group iPhone zero-click, zero-day exploit captured in the wild.** Citizen Lab, a research group at the University of Toronto, has found evidence that the NSO Group, an Israeli cyberarms firm, has developed a zero-click, zero-day exploit for iPhones. This means that the exploit can be used to take control of an iPhone without the user needing to click on any malicious links or open any infected files.\\n* **Chrome now tracks users and shares a “topic” list with advertisers.** Google has updated its Chrome browser to include a new feature that tracks users' browsing activity and shares it with advertisers. The feature, called Topics, is designed to be more privacy-friendly than previous tracking methods, but it has still been met with criticism from privacy advocates.\\n* **UK pulls back from clash with Big Tech over private messaging.** The UK government has backed down from its plans to force tech companies to break encryption on private messages. The move comes after a backlash from privacy advocates and tech companies, who argued that the plans would make it easier for criminals to communicate without being caught.\\n* **North Korean campaign targeting security researchers.** Google has warned that North Korean hackers are targeting security researchers with a new phishing campaign. The campaign uses emails that appear to be from legitimate security companies in order to trick researchers into clicking on malicious links.\\n* **Mulvad on Tailscale: Privately browse the web.** Mullvad, a VPN provider, has announced a new integration with Tailscale, a zero-trust networking platform. The integration allows Mullvad users to securely access Tailscale networks without having to expose their IP address.\\n\\nThese are just a few of the latest news from Hacker News. For more news, you can visit the website or follow Hacker News on social media.\"],[],null,null,null,true,null,null,\"en\",null,null,[null,null,null,null,null,[[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,[null,null,null,null,null,null,true],null,null,null,1]],null,null,null,null,null,null,null,null,null,null,null,null,null,[[]]],null,false,true,true,null,null,false]],[\"Tokyo, Japan\",\"SWML_DESCRIPTION_FROM_YOUR_INTERNET_ADDRESS\",false,[[[null,null,null,[[300,200],null,null,[[347039741,1384534489],[366484097,1408471723]]]]],[[2,null,null,null,null,[null,null,null,[[[356761919,1396503106],121982.98,1931574222,1,864863983]]]]],null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,[null,null,null,null,null,null,null,true]],\"//www.google.com/maps/vt/data\\u003ddcowxztCYYWOy2a7aGifaw0pn9r8S9O4dtVT9IRgNR1__NFCnNvkmWbTAleKalr6JSSMo3Zv2r-ne0h-LhGOXfiemw1L7w-C4eycl9Ljz9a8-hcxgoABkkGXcWMGm7w2Jg9D9TXzDFVtRYg1jQl37Sdw3rIp6xNVxyMg2KIY6KVwhbpo3U-CxHeIm_vR7Q\"],null,null,\"JP\",[]]"]]`

const expAnswer = "Sure, here are some of the latest news from Hacker News on September 9, 2023:\n\n* **NSO group iPhone zero-click, zero-day exploit captured in the wild.** Citizen Lab, a research group at the University of Toronto, has released details of a zero-click exploit developed by the NSO Group that can be used to remotely take control of iPhones without the need for any user interaction. The exploit is believed to have been used by the NSO Group to target journalists, activists, and government officials.\n* **Chrome now tracks users and shares a “topic” list with advertisers.** Google has updated its Chrome browser to include a new feature that tracks users' browsing activity and shares it with advertisers. The feature, called Topics, is designed to replace the previous Interest-based advertising feature. However, critics have argued that Topics is still a form of tracking and that it could be used to build detailed profiles of users.\n* **UK pulls back from clash with Big Tech over private messaging.** The UK government has announced that it will not be pursuing legislation that would have forced tech companies to break encryption in order to facilitate government surveillance. The decision was met with relief by privacy advocates, who had warned that the legislation would have had a chilling effect on free speech.\n* **Internet-connected cars fail privacy and security tests conducted by Mozilla.** Mozilla has published the results of a study that found that many internet-connected cars are vulnerable to privacy and security attacks. The study found that many cars collect and transmit personal data without users' knowledge or consent, and that they are often vulnerable to hacking attacks.\n* **North Korean campaign targeting security researchers.** Google has warned that a North Korean hacking group is targeting security researchers with phishing emails. The emails are designed to trick researchers into clicking on malicious links or opening attachments that contain malware.\n\nThese are just a few of the latest news from Hacker News. For more news, you can visit the website or follow Hacker News on social media."

func TestParser(t *testing.T) {
	answer, err := parse(respText)

	assert.Nil(t, err)

	assert.Equal(t, "c_5d1d4a9e973bc35a", answer.ConversationID)
	assert.Equal(t, "r_5d1d4a9e973bc013", answer.ResponseID)
	assert.Equal(t, "latest news from hackernews", answer.TextQuery)

	assert.Equal(t, expAnswer, answer.Content)
}
