Refactor bucket delete and bucket policy (#5580)

This commit adds the bucket delete and bucket policy functionalities
to the browser.

Part of rewriting the browser code to follow best practices and
guidelines of React (issues #5409 and #5410)

The backend code has been modified by @krishnasrinivas to prevent
issue #4498 from occuring. The relevant changes have been made to the
code according to the latest commit and the unit tests in the backend.
This commit also addresses issue #5449.
This commit is contained in:
Kaan Kabalak
2018-02-27 19:14:49 -08:00
committed by Harshavardhana
parent 416841869a
commit a6adef0bdf
23 changed files with 836 additions and 204 deletions

View File

@@ -26,6 +26,9 @@ jest.mock("../../web", () => ({
}),
MakeBucket: jest.fn(() => {
return Promise.resolve()
}),
DeleteBucket: jest.fn(() => {
return Promise.resolve()
})
}))
@@ -43,7 +46,7 @@ describe("Buckets actions", () => {
{ type: "buckets/SET_LIST", buckets: ["test1", "test2"] },
{ type: "buckets/SET_CURRENT_BUCKET", bucket: "test1" }
]
return store.dispatch(actionsBuckets.fetchBuckets()).then(() => {
return store.dispatch(actionsBuckets.fetchBuckets("list")).then(() => {
const actions = store.getActions()
expect(actions).toEqual(expectedActions)
})
@@ -57,7 +60,7 @@ describe("Buckets actions", () => {
{ type: "buckets/SET_CURRENT_BUCKET", bucket: "test2" }
]
window.location
return store.dispatch(actionsBuckets.fetchBuckets()).then(() => {
return store.dispatch(actionsBuckets.fetchBuckets("list")).then(() => {
const actions = store.getActions()
expect(actions).toEqual(expectedActions)
})
@@ -71,7 +74,7 @@ describe("Buckets actions", () => {
{ type: "buckets/SET_CURRENT_BUCKET", bucket: "test1" }
]
window.location
return store.dispatch(actionsBuckets.fetchBuckets()).then(() => {
return store.dispatch(actionsBuckets.fetchBuckets("list")).then(() => {
const actions = store.getActions()
expect(actions).toEqual(expectedActions)
})
@@ -107,6 +110,36 @@ describe("Buckets actions", () => {
expect(actions).toEqual(expectedActions)
})
it("creates buckets/SHOW_BUCKET_POLICY for showBucketPolicy", () => {
const store = mockStore()
const expectedActions = [
{ type: "buckets/SHOW_BUCKET_POLICY", show: true }
]
store.dispatch(actionsBuckets.showBucketPolicy())
const actions = store.getActions()
expect(actions).toEqual(expectedActions)
})
it("creates buckets/SHOW_BUCKET_POLICY for hideBucketPolicy", () => {
const store = mockStore()
const expectedActions = [
{ type: "buckets/SHOW_BUCKET_POLICY", show: false }
]
store.dispatch(actionsBuckets.hideBucketPolicy())
const actions = store.getActions()
expect(actions).toEqual(expectedActions)
})
it("creates buckets/SET_POLICIES action", () => {
const store = mockStore()
const expectedActions = [
{ type: "buckets/SET_POLICIES", policies: ["test1", "test2"] }
]
store.dispatch(actionsBuckets.setPolicies(["test1", "test2"]))
const actions = store.getActions()
expect(actions).toEqual(expectedActions)
})
it("creates buckets/ADD action", () => {
const store = mockStore()
const expectedActions = [{ type: "buckets/ADD", bucket: "test" }]
@@ -115,6 +148,14 @@ describe("Buckets actions", () => {
expect(actions).toEqual(expectedActions)
})
it("creates buckets/REMOVE action", () => {
const store = mockStore()
const expectedActions = [{ type: "buckets/REMOVE", bucket: "test" }]
store.dispatch(actionsBuckets.removeBucket("test"))
const actions = store.getActions()
expect(actions).toEqual(expectedActions)
})
it("creates buckets/ADD and buckets/SET_CURRENT_BUCKET after creating the bucket", () => {
const store = mockStore()
const expectedActions = [
@@ -126,4 +167,19 @@ describe("Buckets actions", () => {
expect(actions).toEqual(expectedActions)
})
})
it("creates alert/SET, buckets/REMOVE, buckets/SET_LIST and buckets/SET_CURRENT_BUCKET " +
"after deleting the bucket", () => {
const store = mockStore()
const expectedActions = [
{ type: "alert/SET", alert: {id: 0, message: "Bucket 'test3' has been deleted.", type: "info"} },
{ type: "buckets/REMOVE", bucket: "test3" },
{ type: "buckets/SET_LIST", buckets: ["test1", "test2"] },
{ type: "buckets/SET_CURRENT_BUCKET", bucket: "test1" }
]
return store.dispatch(actionsBuckets.deleteBucket("test3")).then(() => {
const actions = store.getActions()
expect(actions).toEqual(expectedActions)
})
})
})