mirror of
https://github.com/jellyfin/jellyfin-expo.git
synced 2024-11-27 00:00:26 +00:00
Add test for ServerStore deserializer
This commit is contained in:
parent
0a1c471d2a
commit
035881ed71
@ -10,6 +10,13 @@ import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import ServerModel from '../models/ServerModel';
|
||||
|
||||
export const DESERIALIZER = data => data.map(server => {
|
||||
// Migrate from old url format
|
||||
// TODO: Remove migration in next minor release
|
||||
const url = server.url.href || server.url;
|
||||
return new ServerModel(server.id, new URL(url), server.info);
|
||||
});
|
||||
|
||||
export default class ServerStore {
|
||||
servers = []
|
||||
|
||||
@ -34,12 +41,7 @@ export default class ServerStore {
|
||||
|
||||
decorate(ServerStore, {
|
||||
servers: [
|
||||
format(data => data.map(value => {
|
||||
// Migrate from old url format
|
||||
// TODO: Remove migration in next minor release
|
||||
const url = value.url.href || value.url;
|
||||
return new ServerModel(value.id, new URL(url), value.info);
|
||||
})),
|
||||
format(DESERIALIZER),
|
||||
observable
|
||||
],
|
||||
addServer: action,
|
||||
|
@ -6,7 +6,9 @@
|
||||
|
||||
import { URL } from 'url';
|
||||
|
||||
import ServerStore from '../ServerStore';
|
||||
import ServerModel from '../../models/ServerModel';
|
||||
|
||||
import ServerStore, { DESERIALIZER } from '../ServerStore';
|
||||
|
||||
const mockFetchInfo = jest.fn();
|
||||
jest.mock('../../models/ServerModel', () => {
|
||||
@ -61,3 +63,34 @@ describe('ServerStore', () => {
|
||||
expect(mockFetchInfo).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('DESERIALIZER', () => {
|
||||
it('should deserialize to a list of ServerModels', () => {
|
||||
const serialized = [
|
||||
{
|
||||
id: 'TEST1',
|
||||
url: { href: 'https://1.example.com' },
|
||||
info: null
|
||||
},
|
||||
{
|
||||
id: 'TEST2',
|
||||
url: 'https://2.example.com/',
|
||||
info: null
|
||||
}
|
||||
];
|
||||
|
||||
const deserialized = DESERIALIZER(serialized);
|
||||
|
||||
expect(deserialized).toHaveLength(2);
|
||||
|
||||
expect(deserialized[0]).toBeInstanceOf(ServerModel);
|
||||
expect(deserialized[0].id).toBe(serialized[0].id);
|
||||
expect(deserialized[0].url).toBeInstanceOf(URL);
|
||||
expect(deserialized[0].url.href).toBe('https://1.example.com/');
|
||||
|
||||
expect(deserialized[1]).toBeInstanceOf(ServerModel);
|
||||
expect(deserialized[1].id).toBe(serialized[1].id);
|
||||
expect(deserialized[1].url).toBeInstanceOf(URL);
|
||||
expect(deserialized[1].url.href).toBe('https://2.example.com/');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user