<commit_before>import Immutable from 'immutable'
import * as selector from '../../../src/selectors/post'
import {
  clearJSON,
  json,
  stub,
  stubCategories,
  stubPost,
  stubTextRegion,
  stubImageRegion,
  stubEmbedRegion,
} from '../../support/stubs'

describe('post selectors', () => {
  let propsPost
  let state
  let params
  beforeEach(() => {
    stub('post', { authorId: 'statePost', token: 'token1' })
    stub('post', { id: '303', authorId: '666' })
    stub('post', { id: '100', authorId: '666', repostContent: [stubTextRegion()] })
    stub('user', { id: '666', username: '666-username' })
    stub('user', { id: '9', username: 'reposter-username' })
    stubCategories()
    propsPost = stub('post', {
      authorId: '666',
      body: [stubTextRegion(), stubImageRegion(), stubEmbedRegion()],
      commentsCount: 12,
      content: [stubTextRegion(), stubImageRegion(), stubEmbedRegion()],
      contentWarning: 'Content Warning!',
      createdAt: 'Today',
      href: '/post-href',
      id: '666',
      links: {
        repostAuthor: { id: '9' },
        categories: [1, 4],
      },
      loved: true,
      lovesCount: 10,
      repostContent: [stubTextRegion()],
      repostId: '667',
      repostPath: '/repost-path',
      reposted: true,
      repostsCount: 13,
      showComments: true,
      showLovers: true,
      showReposters: true,
      summary: [stubTextRegion(), stubImageRegion()],
      token: 'token<PASSWORD>',
      viewsCount: 1666,
      watching: true,
    })
    state = { authentication: Immutable.Map({ isLoggedIn: true }), json }
  })

  afterEach(() => {
    clearJSON()
    params = {}
  })

  context('#selectPropsPostId', () => {
    it('returns the correct props post id from a postId', () => {
      const props = { postId: '666' }
      expect(selector.selectPropsPostId(state, props)).to.equal('666')
    })

    it('returns the correct props post id from a post', () => {
      const props = { post: propsPost }
      expect(selector.selectPropsPostId(state, props)).to.equal('666')
    })
  })

  context('#selectPropsPostIsRelated', () => {
    it('returns the correct props isRelatedPost', () => {
      const props = { isRelatedPost: true }
      expect(selector.selectPropsPostIsRelated(state, props)).to.equal(true)
    })

    it('returns the correct props post id from a post', () => {
      const props = {}
      expect(selector.selectPropsPostIsRelated(state, props)).to.equal(false)
    })
  })

  context('#selectPropsLocationStateFrom', () => {
    it('returns the correct props isRelatedPost', () => {
      const props = { location: { state: { from: 'PaginatorLink' } } }
      expect(selector.selectPropsLocationStateFrom(state, props)).to.equal('PaginatorLink')
    })

    it('returns the correct props post id from a post', () => {
      const props = {}
      expect(selector.selectPropsLocationStateFrom(state, props)).to.be.null
    })
  })


  context('#selectPosts', () => {
    it('returns posts model out of json', () => {
      expect(selector.selectPosts(state)).to.deep.equal(state.json.get('posts'))
    })
  })

  context('#selectPost', () => {
    it('returns a post from a postId', () => {
      const props = { postId: '1' }
      const post = selector.selectPost(state, props)
      expect(post).to.deep.equal(state.json.get('posts').first())
    })

    it('returns an empty Map if postId is not found', () => {
      const props = { postId: '166666' }
      const post = selector.selectPost(state, props)
      expect(post).to.deep.equal(Immutable.Map())
    })

    it('returns a post from a post.postId', () => {
      const props = { post: state.json.get('posts').first() }
      const post = selector.selectPost(state, props)
      expect(post).to.deep.equal(state.json.get('posts').first())
    })

    it('returns an empty Map if post.postId is not found', () => {
      const props = { post: stubPost({ id: '99999' }, false) }
      const post = selector.selectPost(state, props)
      expect(post).to.deep.equal(Immutable.Map())
    })

    it('returns a post from a token', () => {
      const props = { match: { params: { ...params, token: '<PASSWORD>' } } }
      const post = selector.selectPost(state, props)
      expect(post).to.deep.equal(state.json.getIn(['posts', '666']))
    })

    it('returns an empty Map if token is not found', () => {
      const props = { params: { token: '<PASSWORD>' } }
      const post = selector.selectPost(state, props)
      expect(post).to.deep.equal(Immutable.Map())
    })

    it('returns an empty Map if id and token is not found', () => {
      const props = {}
      const post = selector.selectPost(state, props)
      expect(post).to.deep.equal(Immutable.Map())
    })

    it('returns an empty Map if post is not found', () => {
      const props = {}
      const post = selector.selectPost({ json: Immutable.Map() }, props)
      expect(post).to.deep.equal(Immutable.Map())
    })
  })

  context('#selectPostAuthorId', () => {
    it('returns the post authorId', () => {
      const props = { postId: '666' }
      const result = selector.selectPostAuthorId(state, props)
      expect(result).to.deep.equal('666')
    })
  })

  context('#selectPostBody', () => {
    it('returns the post body', () => {
      const props = { postId: '666' }
      const result = selector.selectPostBody(state, props)
      expect(result.size).to.equal(3)
    })
  })

  context('#selectPostCommentsCount', () => {
    it('returns the post comments count', () => {
      const props = { postId: '666' }
      const result = selector.selectPostCommentsCount(state, props)
      expect(result).to.equal(12)
    })

    it('ensures the comment count does not fall below 0', () => {
      state.json = state.json.setIn(['posts', '666', 'commentsCount'], -1)
      const props = { postId: '666' }
      const result = selector.selectPostCommentsCount(state, props)
      expect(result).to.equal(0)
    })<commit_msg>Added test cases for post redirect<commit_after>import Immutable from 'immutable'
import * as selector from '../../../src/selectors/post'
import {
  clearJSON,
  json,
  stub,
  stubCategories,
  stubPost,
  stubTextRegion,
  stubImageRegion,
  stubEmbedRegion,
} from '../../support/stubs'

describe('post selectors', () => {
  let propsPost
  let state
  let params
  beforeEach(() => {
    stub('post', { authorId: 'statePost', token: 'token1' })
    stub('post', { id: '303', authorId: '666' })
    stub('post', { id: '100', authorId: '666', repostContent: [stubTextRegion()] })
    stub('user', { id: '666', username: '666-username' })
    stub('user', { id: '9', username: 'reposter-username' })
    stubCategories()
    propsPost = stub('post', {
      authorId: '666',
      body: [stubTextRegion(), stubImageRegion(), stubEmbedRegion()],
      commentsCount: 12,
      content: [stubTextRegion(), stubImageRegion(), stubEmbedRegion()],
      contentWarning: 'Content Warning!',
      createdAt: 'Today',
      href: '/post-href',
      id: '666',
      links: {
        repostAuthor: { id: '9' },
        categories: [1, 4],
      },
      loved: true,
      lovesCount: 10,
      repostContent: [stubTextRegion()],
      repostId: '667',
      repostPath: '/repost-path',
      reposted: true,
      repostsCount: 13,
      showComments: true,
      showLovers: true,
      showReposters: true,
      summary: [stubTextRegion(), stubImageRegion()],
      token: '<PASSWORD>',
      viewsCount: 1666,
      watching: true,
    })
    state = { authentication: Immutable.Map({ isLoggedIn: true }), json }
  })

  afterEach(() => {
    clearJSON()
    params = {}
  })

  context('#selectPropsPostId', () => {
    it('returns the correct props post id from a postId', () => {
      const props = { postId: '666' }
      expect(selector.selectPropsPostId(state, props)).to.equal('666')
    })

    it('returns the correct props post id from a post', () => {
      const props = { post: propsPost }
      expect(selector.selectPropsPostId(state, props)).to.equal('666')
    })
  })

  context('#selectPropsPostIsRelated', () => {
    it('returns the correct props isRelatedPost', () => {
      const props = { isRelatedPost: true }
      expect(selector.selectPropsPostIsRelated(state, props)).to.equal(true)
    })

    it('returns the correct props post id from a post', () => {
      const props = {}
      expect(selector.selectPropsPostIsRelated(state, props)).to.equal(false)
    })
  })

  context('#selectPropsLocationStateFrom', () => {
    it('returns the correct props isRelatedPost', () => {
      const props = { location: { state: { from: 'PaginatorLink' } } }
      expect(selector.selectPropsLocationStateFrom(state, props)).to.equal('PaginatorLink')
    })

    it('returns the correct props post id from a post', () => {
      const props = {}
      expect(selector.selectPropsLocationStateFrom(state, props)).to.be.null
    })
  })


  context('#selectPosts', () => {
    it('returns posts model out of json', () => {
      expect(selector.selectPosts(state)).to.deep.equal(state.json.get('posts'))
    })
  })

  context('#selectPost', () => {
    it('returns a post from a postId', () => {
      const props = { postId: '1' }
      const post = selector.selectPost(state, props)
      expect(post).to.deep.equal(state.json.get('posts').first())
    })

    it('returns an empty Map if postId is not found', () => {
      const props = { postId: '166666' }
      const post = selector.selectPost(state, props)
      expect(post).to.deep.equal(Immutable.Map())
    })

    it('returns a post from a post.postId', () => {
      const props = { post: state.json.get('posts').first() }
      const post = selector.selectPost(state, props)
      expect(post).to.deep.equal(state.json.get('posts').first())
    })

    it('returns an empty Map if post.postId is not found', () => {
      const props = { post: stubPost({ id: '99999' }, false) }
      const post = selector.selectPost(state, props)
      expect(post).to.deep.equal(Immutable.Map())
    })

    it('returns a post from a token', () => {
      const props = { match: { params: { ...params, token: 'token<PASSWORD>' } } }
      const post = selector.selectPost(state, props)
      expect(post).to.deep.equal(state.json.getIn(['posts', '666']))
    })

    it('returns an empty Map if token is not found', () => {
      const props = { params: { token: 'token<PASSWORD>' } }
      const post = selector.selectPost(state, props)
      expect(post).to.deep.equal(Immutable.Map())
    })

    it('returns an empty Map if id and token is not found', () => {
      const props = {}
      const post = selector.selectPost(state, props)
      expect(post).to.deep.equal(Immutable.Map())
    })

    it('returns an empty Map if post is not found', () => {
      const props = {}
      const post = selector.selectPost({ json: Immutable.Map() }, props)
      expect(post).to.deep.equal(Immutable.Map())
    })
  })

  context('#selectRecentPost', () => {
    it('returns recent post token', () => {
      expect(selector.selectRecentPost(state)).to.deep.equal(state.json.get('recentPost', Immutable.Map()))
    })
  })

  context('#selectPostAuthorId', () => {
    it('returns the post authorId', () => {
      const props = { postId: '666' }
      const result = selector.selectPostAuthorId(state, props)
      expect(result).to.deep.equal('666')
    })
  })

  context('#selectPostBody', () => {
    it('returns the post body', () => {
      const props = { postId: '666' }
      const result = selector.selectPostBody(state, props)
      expect(result.size).to.equal(3)
    })
  })

  context('#selectPostCommentsCount', () => {
    it('returns the post comments count', () => {
      const props = { postId: '666' }
      const result = selector.selectPostCommentsCount(state, props)
      expect(result).to.equal(12)
    })

    it('ensures the comment count does not fall below 0', () => {
      state.json = state.json.setIn(['posts', '666', 'commentsCount'], -1)
      const props = { postId: '666' }
      const result = selector.selectPostCommentsCount(state, props)
      expect(result).to.equal(0)
    })
{'fraction_non_alphanumeric': 0.1693561666392228, 'fraction_numerical': 0.014819693726329656, 'mean_word_length': 2.9813176007866273, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4604725', 'n_tokens_mistral': 3895, 'n_tokens_neox': 3748, 'n_words': 864}