feat: monorepo

This commit is contained in:
qier222 2022-05-12 02:45:43 +08:00
parent 4d54060a4f
commit 42089d4996
No known key found for this signature in database
GPG key ID: 9C85007ED905F14D
200 changed files with 1530 additions and 1521 deletions

View file

@ -0,0 +1,225 @@
import { expect, test, describe, vi } from 'vitest'
import {
resizeImage,
formatDate,
formatDuration,
cacheCoverColor,
calcCoverColor,
getCoverColor,
storage,
} from '@/web/utils/common'
import { IpcChannels } from '@/shared/IpcChannels'
import { APIs } from '@/shared/CacheAPIs'
test('resizeImage', () => {
expect(resizeImage('https://test.com/test.jpg', 'xs')).toBe(
'https://test.com/test.jpg?param=128y128'
)
expect(resizeImage('https://test.com/test.jpg', 'sm')).toBe(
'https://test.com/test.jpg?param=256y256'
)
expect(resizeImage('https://test.com/test.jpg', 'md')).toBe(
'https://test.com/test.jpg?param=512y512'
)
expect(resizeImage('https://test.com/test.jpg', 'lg')).toBe(
'https://test.com/test.jpg?param=1024y1024'
)
// test http => https
expect(resizeImage('http://test.com/test.jpg', 'xs')).toBe(
'https://test.com/test.jpg?param=128y128'
)
expect(resizeImage('', 'xs')).toBe('')
})
test('formatDate', () => {
const time = 1650590574000
expect(formatDate(time)).toBe('2022年04月22日')
expect(formatDate(time, 'en')).toBe('Apr 22, 2022')
expect(formatDate(time, 'en', 'YYYY-MMM-DD')).toBe('2022-Apr-22')
expect(formatDate(time, 'zh-CN')).toBe('2022年04月22日')
expect(formatDate(time, 'zh-TW')).toBe('2022年04月22日')
})
test('formatDuration', () => {
expect(formatDuration(1000)).toBe('0:01')
expect(formatDuration(60000)).toBe('1:00')
expect(formatDuration(3600000)).toBe('1:00:00')
expect(formatDuration(3700000)).toBe('1:01:40')
expect(formatDuration(3600000, 'en', 'hh[hr] mm[min]')).toBe('1 hr')
expect(formatDuration(3600000, 'zh-CN', 'hh[hr] mm[min]')).toBe('1 小时')
expect(formatDuration(3600000, 'zh-TW', 'hh[hr] mm[min]')).toBe('1 小時')
expect(formatDuration(3700000, 'en', 'hh[hr] mm[min]')).toBe('1 hr 1 min')
expect(formatDuration(3700000, 'zh-CN', 'hh[hr] mm[min]')).toBe(
'1 小时 1 分钟'
)
expect(formatDuration(3700000, 'zh-TW', 'hh[hr] mm[min]')).toBe(
'1 小時 1 分鐘'
)
expect(formatDuration(0)).toBe('0:00')
expect(formatDuration(0, 'en', 'hh[hr] mm[min]')).toBe('0 min')
expect(formatDuration(0, 'zh-CN', 'hh[hr] mm[min]')).toBe('0 分钟')
})
describe('cacheCoverColor', () => {
test('cache with valid url', () => {
vi.stubGlobal('ipcRenderer', {
send: (channel: IpcChannels, ...args: any[]) => {
expect(channel).toBe(IpcChannels.CacheCoverColor)
expect(args[0].api).toBe(APIs.CoverColor)
expect(args[0].query).toEqual({
id: '109951165911363',
color: '#fff',
})
},
})
const sendSpy = vi.spyOn(window.ipcRenderer as any, 'send')
cacheCoverColor(
'https://p2.music.126.net/2qW-OYZod7SgrzxTwtyBqA==/109951165911363.jpg?param=256y256',
'#fff'
)
expect(sendSpy).toHaveBeenCalledTimes(1)
vi.stubGlobal('ipcRenderer', undefined)
})
test('cache with invalid url', () => {
vi.stubGlobal('ipcRenderer', {
send: (channel: IpcChannels, ...args: any[]) => {
expect(channel).toBe(IpcChannels.CacheCoverColor)
expect(args[0].api).toBe(APIs.CoverColor)
expect(args[0].query).toEqual({
id: '',
color: '#fff',
})
},
})
const sendSpy = vi.spyOn(window.ipcRenderer as any, 'send')
cacheCoverColor('not a valid url', '#fff')
expect(sendSpy).toHaveBeenCalledTimes(0)
vi.stubGlobal('ipcRenderer', undefined)
})
})
test('calcCoverColor', async () => {
vi.mock('color.js', () => {
return {
average: vi.fn(
() =>
new Promise(resolve => {
resolve('#fff')
})
),
}
})
vi.stubGlobal('ipcRenderer', {
send: (channel: IpcChannels, ...args: any[]) => {
expect(channel).toBe(IpcChannels.CacheCoverColor)
expect(args[0].api).toBe(APIs.CoverColor)
expect(args[0].query).toEqual({
id: '109951165911363',
color: '#808080',
})
},
})
const sendSpy = vi.spyOn(window.ipcRenderer as any, 'send')
expect(
await calcCoverColor(
'https://p2.music.126.net/2qW-OYZod7SgrzxTwtyBqA==/109951165911363.jpg?param=256y256'
)
).toBe('#808080')
vi.stubGlobal('ipcRenderer', undefined)
})
describe('getCoverColor', () => {
test('hit cache', async () => {
vi.stubGlobal('ipcRenderer', {
sendSync: (channel: IpcChannels, ...args: any[]) => {
expect(channel).toBe(IpcChannels.GetApiCacheSync)
expect(args[0].api).toBe(APIs.CoverColor)
expect(args[0].query).toEqual({
id: '109951165911363',
})
return '#fff'
},
})
const sendSyncSpy = vi.spyOn(window.ipcRenderer as any, 'sendSync')
expect(
await getCoverColor(
'https://p2.music.126.net/2qW-OYZod7SgrzxTwtyBqA==/109951165911363.jpg?param=256y256'
)
).toBe('#fff')
expect(sendSyncSpy).toHaveBeenCalledTimes(1)
vi.stubGlobal('ipcRenderer', undefined)
})
test('did not hit cache', async () => {
vi.stubGlobal('ipcRenderer', {
sendSync: (channel: IpcChannels, ...args: any[]) => {
expect(channel).toBe(IpcChannels.GetApiCacheSync)
expect(args[0].api).toBe(APIs.CoverColor)
expect(args[0].query).toEqual({
id: '109951165911363',
})
return undefined
},
send: () => {
//
},
})
const sendSyncSpy = vi.spyOn(window.ipcRenderer as any, 'sendSync')
const sendSpy = vi.spyOn(window.ipcRenderer as any, 'send')
expect(
await getCoverColor(
'https://p2.music.126.net/2qW-OYZod7SgrzxTwtyBqA==/109951165911363.jpg?param=256y256'
)
).toBe('#808080')
expect(sendSyncSpy).toHaveBeenCalledTimes(1)
expect(sendSpy).toHaveBeenCalledTimes(1)
vi.stubGlobal('ipcRenderer', undefined)
})
test('invalid url', async () => {
expect(await getCoverColor('not a valid url')).toBe(undefined)
})
})
test('storage', () => {
const mockLocalStorage: any = {
test: {
key: 'value',
},
}
vi.stubGlobal('localStorage', {
getItem: (key: string) => {
return mockLocalStorage[key] ?? undefined
},
setItem: (key: string, value: string) => {
expect(key).toBe('test')
expect(value).toEqual(`{"key":"value2"}`)
mockLocalStorage[key] = value
},
})
expect(storage.set('test', { key: 'value2' })).toBe(undefined)
expect(storage.get('test')).toEqual({ key: 'value2' })
expect(storage.get('test2')).toBe(null)
vi.stubGlobal('localStorage', undefined)
})

View file

@ -0,0 +1,185 @@
import { expect, test, describe, vi, beforeEach, afterEach } from 'vitest'
import {
setCookies,
getCookie,
removeCookie,
parseCookies,
removeAllCookies,
} from '@/web/utils/cookie'
import Cookies from 'js-cookie'
describe('parseCookies', () => {
test('parse simple cookies', () => {
expect(parseCookies('test=test; test2=test2')).toEqual([
{
key: 'test',
value: 'test',
},
{
key: 'test2',
value: 'test2',
},
])
})
test('parse cookies with empty value, expires and double semicolon', () => {
expect(
parseCookies(
'test=; test2=test2; Expires=Wed, 21 Oct 2015 07:28:00 GMT;;'
)
).toEqual([
{
key: 'test',
value: '',
},
{
key: 'test2',
value: 'test2',
},
])
})
test('prase cookies with max-age', () => {
expect(parseCookies('test2=test2; Max-Age=604800')).toEqual([
{
key: 'test2',
value: 'test2',
options: {
expires: 7,
},
},
])
})
test('parse cookies with invalid max-age', () => {
expect(parseCookies('test2=test2; Max-Age=invalid')).toEqual([
{
key: 'test2',
value: 'test2',
},
])
})
test('parse cookie with path', () => {
expect(parseCookies('test2=test2; Path=/')).toEqual([
{
key: 'test2',
value: 'test2',
options: {
path: '/',
},
},
])
})
test('parse cookie with HTTPOnly', () => {
expect(parseCookies('test2=test2; HttpOnly')).toEqual([
{
key: 'test2',
value: 'test2',
},
])
})
})
describe('setCookies', () => {
beforeEach(() => {
removeAllCookies()
})
afterEach(() => {
removeAllCookies()
})
test('set one cookie', () => {
const setSpy = vi.spyOn(Cookies, 'set')
expect(setCookies('test=test')).toBe(undefined)
expect(setSpy).toHaveBeenCalledTimes(1)
expect(Cookies.get('test')).toBe('test')
})
test('set multiple cookies', () => {
const setSpy = vi.spyOn(Cookies, 'set')
expect(setCookies('test=test; test2=test2;')).toBe(undefined)
expect(setSpy).toHaveBeenCalledTimes(2)
expect(Cookies.get('test')).toBe('test')
expect(Cookies.get('test2')).toBe('test2')
})
test('set Netease qr code login cookies', () => {
const setSpy = vi.spyOn(Cookies, 'set')
expect(
setCookies(
'MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/eapi/clientlog; HTTPOnly;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/api/clientlog; HTTPOnly;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/openapi/clientlog; HTTPOnly;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/api/feedback; HTTPOnly;MUSIC_SNS=; Max-Age=0; Expires=Thu, 14 Apr 2022 08:25:58 GMT; Path=/;MUSIC_U=a0d026bc508b3b4427c06d7c2aa66c200764eceb4734513f6caf9308528ac1369f00530f; Max-Age=15552000; Expires=Tue, 11 Oct 2022 08:25:58 GMT; Path=/; HTTPOnly;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/weapi/clientlog; HTTPOnly;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/wapi/clientlog; HTTPOnly;__csrf=5b947e26d720eeaf28700786d41ea5dd; Max-Age=1296010; Expires=Fri, 29 Apr 2022 08:26:08 GMT; Path=/;;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/weapi/feedback; HTTPOnly;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/neapi/feedback; HTTPOnly;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/weapi/clientlog; HTTPOnly;MUSIC_A_T=; Max-Age=0; Expires=Thu, 14 Apr 2022 08:25:58 GMT; Path=/;;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/wapi/feedback; HTTPOnly;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/neapi/feedback; HTTPOnly;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/api/clientlog; HTTPOnly;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/api/feedback; HTTPOnly;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/weapi/feedback; HTTPOnly;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/neapi/clientlog; HTTPOnly;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/eapi/feedback; HTTPOnly;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/neapi/clientlog; HTTPOnly;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/eapi/clientlog; HTTPOnly;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/wapi/feedback; HTTPOnly;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/openapi/clientlog; HTTPOnly;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/wapi/clientlog; HTTPOnly;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:40:05 GMT; Path=/eapi/feedback; HTTPOnly'
)
).toBe(undefined)
expect(setSpy).toHaveBeenCalledTimes(26)
expect(Cookies.get('MUSIC_U')).toBe(
'a0d026bc508b3b4427c06d7c2aa66c200764eceb4734513f6caf9308528ac1369f00530f'
)
expect(Cookies.get('__csrf')).toBe('5b947e26d720eeaf28700786d41ea5dd')
expect(Cookies.get('MUSIC_R_T')).toBe(undefined) // because of path is not /
expect(Cookies.get('MUSIC_A_T')).toBe(undefined) // because of path is not /
})
test('set Netease email login cookies', () => {
const setSpy = vi.spyOn(Cookies, 'set')
expect(
setCookies(
'__remember_me=true; Max-Age=1296000; Expires=Fri, 29 Apr 2022 08:41:59 GMT; Path=/;;MUSIC_A_T=1519475931796; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/wapi/clientlog;;MUSIC_A_T=; Max-Age=0; Expires=Thu, 14 Apr 2022 08:41:59 GMT; Path=/;;MUSIC_A_T=1519475931796; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/eapi/clientlog;;MUSIC_A_T=1519475931796; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/neapi/clientlog;;MUSIC_R_T=1519475931800; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/wapi/feedback;;__csrf=be948ee03ab9aa0c4cc0bfd7a6276728; Max-Age=1296010; Expires=Fri, 29 Apr 2022 08:42:09 GMT; Path=/;;MUSIC_R_T=1519475931800; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/openapi/clientlog;;MUSIC_U=1239b6c1217d8cd240df9c8fa15e99a69c3fa0e6a9dfac6b5b7c2a817be2b9a20807b5c6b97f6b5; Max-Age=1296000; Expires=Fri, 29 Apr 2022 08:41:59 GMT; Path=/;;MUSIC_R_T=1519475931800; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/eapi/feedback;;MUSIC_R_T=1519475931800; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/eapi/clientlog;;MUSIC_R_T=1519475931800; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/wapi/clientlog;;MUSIC_A_T=1519475931796; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/api/feedback;;MUSIC_R_T=1519475931800; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/api/clientlog;;MUSIC_SNS=; Max-Age=0; Expires=Thu, 14 Apr 2022 08:41:59 GMT; Path=/;MUSIC_A_T=1519475931796; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/eapi/feedback;;MUSIC_R_T=1519475931800; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/weapi/clientlog;;MUSIC_A_T=1519475931796; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/weapi/clientlog;;MUSIC_A_T=1519475931796; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/openapi/clientlog;;MUSIC_R_T=1519475931800; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/weapi/feedback;;MUSIC_R_T=; Max-Age=0; Expires=Thu, 14 Apr 2022 08:41:59 GMT; Path=/;;MUSIC_R_T=1519475931800; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/neapi/feedback;;MUSIC_A_T=1519475931796; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/weapi/feedback;;MUSIC_A_T=1519475931796; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/neapi/feedback;;MUSIC_R_T=1519475931800; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/api/feedback;;MUSIC_A_T=1519475931796; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/api/clientlog;;MUSIC_R_T=1519475931800; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/neapi/clientlog;;MUSIC_A_T=1519475931796; Max-Age=2147483647; Expires=Tue, 2 May 2090 11:56:06 GMT; Path=/wapi/feedback;'
)
).toBe(undefined)
expect(setSpy).toHaveBeenCalledTimes(28)
expect(Cookies.get('MUSIC_U')).toBe(
'1239b6c1217d8cd240df9c8fa15e99a69c3fa0e6a9dfac6b5b7c2a817be2b9a20807b5c6b97f6b5'
)
expect(Cookies.get('__remember_me')).toBe('true')
expect(Cookies.get('__csrf')).toBe('be948ee03ab9aa0c4cc0bfd7a6276728')
expect(Cookies.get('MUSIC_R_T')).toBe(undefined) // because of path is not /
expect(Cookies.get('MUSIC_A_T')).toBe(undefined) // because of path is not /
})
test('set Netease phone login cookies', () => {
const setSpy = vi.spyOn(Cookies, 'set')
expect(
setCookies(
'MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/openapi/clientlog;;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/eapi/feedback;;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/weapi/clientlog;;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/weapi/feedback;;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/wapi/clientlog;;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/api/feedback;;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/wapi/feedback;;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/api/clientlog;;NMTID=00OEhPKoaEluGvd9kgutai-iADpQkEAAAGAJz_PTQ; Max-Age=315360000; Expires=Sun, 11 Apr 2032 08:45:34 GMT; Path=/;;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/eapi/clientlog;;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/api/clientlog;;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/openapi/clientlog;;MUSIC_U=a0d026bc508b3b4427c06d7c2aa66c204ba2a162576a513197f262a1067ea44651; Max-Age=1296000; Expires=Fri, 29 Apr 2022 08:45:34 GMT; Path=/;;MUSIC_SNS=; Max-Age=0; Expires=Thu, 14 Apr 2022 08:45:34 GMT; Path=/;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/wapi/clientlog;;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/eapi/clientlog;;__csrf=78328f711c179391b096a67ad9d0f08b; Max-Age=1296010; Expires=Fri, 29 Apr 2022 08:45:44 GMT; Path=/;;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/neapi/feedback;;__remember_me=true; Max-Age=1296000; Expires=Fri, 29 Apr 2022 08:45:34 GMT; Path=/;;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/weapi/clientlog;;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/eapi/feedback;;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/api/feedback;;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/weapi/feedback;;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/neapi/clientlog;;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/neapi/feedback;;MUSIC_A_T=1376792466000; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/neapi/clientlog;;MUSIC_R_T=1376792525993; Max-Age=2147483647; Expires=Tue, 02 May 2090 11:59:41 GMT; Path=/wapi/feedback;'
)
).toBe(undefined)
expect(setSpy).toHaveBeenCalledTimes(27)
expect(Cookies.get('MUSIC_U')).toBe(
'a0d026bc508b3b4427c06d7c2aa66c204ba2a162576a513197f262a1067ea44651'
)
expect(Cookies.get('__remember_me')).toBe('true')
expect(Cookies.get('__csrf')).toBe('78328f711c179391b096a67ad9d0f08b')
expect(Cookies.get('NMTID')).toBe(
'00OEhPKoaEluGvd9kgutai-iADpQkEAAAGAJz_PTQ'
)
expect(Cookies.get('MUSIC_R_T')).toBe(undefined) // because of path is not /
expect(Cookies.get('MUSIC_A_T')).toBe(undefined) // because of path is not /
})
})
test('getCookie', () => {
removeAllCookies()
document.cookie = 'test=test'
expect(getCookie('test')).toBe('test')
removeAllCookies()
})
test('removeCookie', () => {
removeAllCookies()
document.cookie = 'test=test'
removeCookie('test')
expect(getCookie('test')).toBe(undefined)
expect(document.cookie).toBe('')
removeAllCookies()
})
test('removeAllCookies', () => {
document.cookie = 'test=test'
document.cookie = 'test2=test2'
removeAllCookies()
expect(document.cookie).toBe('')
})