{"size": 5208, "ext": "js", "max_stars_repo_path": "webui/src/store/udp/mutations.spec.js", "max_stars_repo_name": "sidharthv96/traefik", "max_stars_repo_stars_event_min_datetime": "2016-02-24T21:43:21.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-16T07:58:53.000Z", "max_issues_repo_path": "webui/src/store/udp/mutations.spec.js", "max_issues_repo_name": "sidharthv96/traefik", "max_issues_repo_issues_event_min_datetime": "2016-02-24T18:20:51.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-16T08:33:31.000Z", "max_forks_repo_path": "webui/src/store/udp/mutations.spec.js", "max_forks_repo_name": "sidharthv96/traefik", "max_forks_repo_forks_event_min_datetime": "2016-02-25T19:03:33.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-15T05:59:55.000Z"}
{"max_stars_count": 30611, "max_issues_count": 5327, "max_forks_count": 4010, "avg_line_length": 26.303030303, "max_line_length": 73, "alphanum_fraction": 0.5662442396}
import { expect } from 'chai'
import store from './index.js'

const {
  getAllRoutersRequest,
  getAllRoutersSuccess,
  getAllRoutersFailure,
  getAllServicesRequest,
  getAllServicesSuccess,
  getAllServicesFailure
} = store.mutations

describe('udp mutations', function () {
  /* Routers */
  describe('udp routers mutations', function () {
    it('getAllRoutersRequest', function () {
      const state = {
        allRouters: {
          items: [{}, {}, {}]
        }
      }

      getAllRoutersRequest(state)

      expect(state.allRouters.loading).to.equal(true)
      expect(state.allRouters.items.length).to.equal(3)
    })

    it('getAllRoutersSuccess page 1', function () {
      const state = {
        allRouters: {
          loading: true
        }
      }

      const data = {
        body: {
          data: [{}, {}, {}],
          total: 3
        },
        query: 'test query',
        status: 'warning',
        page: 1
      }

      getAllRoutersSuccess(state, data)

      expect(state.allRouters.loading).to.equal(false)
      expect(state.allRouters.total).to.equal(3)
      expect(state.allRouters.items.length).to.equal(3)
      expect(state.allRouters.currentPage).to.equal(1)
      expect(state.allRouters.currentQuery).to.equal('test query')
      expect(state.allRouters.currentStatus).to.equal('warning')
    })

    it('getAllRoutersSuccess page 2', function () {
      const state = {
        allRouters: {
          loading: false,
          items: [{ id: 1 }, { id: 2 }, { id: 3 }],
          total: 3,
          currentPage: 1,
          currentQuery: 'test query',
          currentStatus: 'warning'
        }
      }

      const data = {
        body: {
          data: [{ id: 4 }, { id: 5 }, { id: 6 }, { id: 7 }],
          total: 4
        },
        query: 'test query',
        status: 'warning',
        page: 2
      }

      getAllRoutersSuccess(state, data)

      expect(state.allRouters.loading).to.equal(false)
      expect(state.allRouters.total).to.equal(7)
      expect(state.allRouters.items.length).to.equal(7)
      expect(state.allRouters.currentPage).to.equal(2)
      expect(state.allRouters.currentQuery).to.equal('test query')
      expect(state.allRouters.currentStatus).to.equal('warning')
    })

    it('getAllRoutersFailing', function () {
      const state = {
        allRouters: {
          items: [{}, {}, {}],
          loading: true
        }
      }

      const error = { message: 'invalid request: page: 3, per_page: 10' }

      getAllRoutersFailure(state, error)

      expect(state.allRouters.loading).to.equal(false)
      expect(state.allRouters.endReached).to.equal(true)
      expect(state.allRouters.items.length).to.equal(3)
    })
  })

  /* Services */
  describe('udp services mutations', function () {
    it('getAllServicesRequest', function () {
      const state = {
        allServices: {
          items: [{}, {}, {}]
        }
      }

      getAllServicesRequest(state)

      expect(state.allServices.loading).to.equal(true)
      expect(state.allServices.items.length).to.equal(3)
    })

    it('getAllServicesSuccess page 1', function () {
      const state = {
        allServices: {
          loading: true
        }
      }

      const data = {
        body: {
          data: [{}, {}, {}],
          total: 3
        },
        query: 'test query',
        status: 'warning',
        page: 1
      }

      getAllServicesSuccess(state, data)

      expect(state.allServices.loading).to.equal(false)
      expect(state.allServices.total).to.equal(3)
      expect(state.allServices.items.length).to.equal(3)
      expect(state.allServices.currentPage).to.equal(1)
      expect(state.allServices.currentQuery).to.equal('test query')
      expect(state.allServices.currentStatus).to.equal('warning')
    })

    it('getAllServicesSuccess page 2', function () {
      const state = {
        allServices: {
          loading: false,
          items: [{ id: 1 }, { id: 2 }, { id: 3 }],
          total: 3,
          currentPage: 1,
          currentQuery: 'test query',
          currentStatus: 'warning'
        }
      }

      const data = {
        body: {
          data: [{ id: 4 }, { id: 5 }, { id: 6 }, { id: 7 }],
          total: 4
        },
        query: 'test query',
        status: 'warning',
        page: 2
      }

      getAllServicesSuccess(state, data)

      expect(state.allServices.loading).to.equal(false)
      expect(state.allServices.total).to.equal(7)
      expect(state.allServices.items.length).to.equal(7)
      expect(state.allServices.currentPage).to.equal(2)
      expect(state.allServices.currentQuery).to.equal('test query')
      expect(state.allServices.currentStatus).to.equal('warning')
    })

    it('getAllServicesFailing', function () {
      const state = {
        allServices: {
          items: [{}, {}, {}],
          loading: true
        }
      }

      const error = { message: 'invalid request: page: 3, per_page: 10' }

      getAllServicesFailure(state, error)

      expect(state.allServices.loading).to.equal(false)
      expect(state.allServices.endReached).to.equal(true)
      expect(state.allServices.items.length).to.equal(3)
    })
  })
})
