UNPKG

@twreporter/redux

Version:

redux actions and reducers for twreporter website

97 lines (95 loc) 3.29 kB
"use strict"; var _denormalizeAsset = require("../denormalize-asset"); /* global expect, test, describe */ describe('denormalize assets testing', function () { var postEntities = { 'post-slug-1': { slug: 'post-slug-1', relateds: ['post-slug-2', 'post-slug-3'] }, 'post-slug-2': { slug: 'post-slug-2', relateds: ['post-slug-1', 'post-slug-3'] }, 'post-slug-3': { slug: 'post-slug-3', relateds: ['post-slug-1', 'post-slug-2'] }, 'post-slug-4': { slug: 'post-slug-4', topics: 'topic-slug-1' } }; var topicEntities = { 'topic-slug-1': { slug: 'topic-slug-1', relateds: ['post-slug-4'] }, 'topic-slug-2': { slug: 'topic-slug-2', relateds: ['post-slug-1', 'post-slug-2'] } }; describe('denormalize posts', function () { test('should handle empty array', function () { expect((0, _denormalizeAsset.denormalizePosts)([], postEntities)).toEqual([]); }); test('should handle single slug', function () { expect((0, _denormalizeAsset.denormalizePosts)('post-slug-1', postEntities)).toEqual([{ slug: 'post-slug-1', relateds: ['post-slug-2', 'post-slug-3'] }]); }); test('should handle multiple slugs', function () { expect((0, _denormalizeAsset.denormalizePosts)(['post-slug-1', 'post-slug-2'], postEntities)).toEqual([{ slug: 'post-slug-1', relateds: ['post-slug-2', 'post-slug-3'] }, { slug: 'post-slug-2', relateds: ['post-slug-1', 'post-slug-3'] }]); }); test('shoulde return new object', function () { var post = (0, _denormalizeAsset.denormalizePosts)(['post-slug-1'], postEntities); expect(post).not.toBe(postEntities['post-slug-1']); expect(post[0].relateds).not.toBe(postEntities['post-slug-1'].relateds); }); }); describe('denormalize topics', function () { test('should handle empty array', function () { expect((0, _denormalizeAsset.denormalizeTopics)([], topicEntities, postEntities)).toEqual([]); }); test('should handle single slug', function () { expect((0, _denormalizeAsset.denormalizeTopics)('topic-slug-1', topicEntities, postEntities)).toEqual([{ slug: 'topic-slug-1', relateds: [{ slug: 'post-slug-4', topics: 'topic-slug-1' }] }]); }); test('should handle multiple slugs', function () { expect((0, _denormalizeAsset.denormalizeTopics)(['topic-slug-1', 'topic-slug-2'], topicEntities, postEntities)).toEqual([{ slug: 'topic-slug-1', relateds: [{ slug: 'post-slug-4', topics: 'topic-slug-1' }] }, { slug: 'topic-slug-2', relateds: [{ slug: 'post-slug-1', relateds: ['post-slug-2', 'post-slug-3'] }, { slug: 'post-slug-2', relateds: ['post-slug-1', 'post-slug-3'] }] }]); }); test('shoulde return new object', function () { var topic = (0, _denormalizeAsset.denormalizeTopics)(['topic-slug-1'], topicEntities, postEntities); expect(topic[0]).not.toBe(topicEntities['topic-slug-1']); expect(topic[0].relateds).not.toBe(topicEntities['topic-slug-1'].relateds); }); }); });