mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Finishing off the merge with localStorage refactoring with sekrets
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
Darkswarm.factory 'Order', ($resource, order, $http, Flash, Navigation, storage)->
|
||||
Darkswarm.factory 'Order', ($resource, order, $http, flash, Navigation, storage)->
|
||||
new class Order
|
||||
errors: {}
|
||||
secrets: {}
|
||||
@@ -24,7 +24,8 @@ Darkswarm.factory 'Order', ($resource, order, $http, Flash, Navigation, storage)
|
||||
Navigation.go data.path
|
||||
.error (response, status)=>
|
||||
@errors = response.errors
|
||||
Flash.loadFlash(response.flash)
|
||||
flash.error = response.flash?.error
|
||||
flash.success = response.flash?.notice
|
||||
|
||||
# Rails wants our Spree::Address data to be provided with _attributes
|
||||
preprocess: ->
|
||||
|
||||
@@ -13,7 +13,7 @@ describe "CheckoutCtrl", ->
|
||||
bindFieldsToLocalStorage: ->
|
||||
order:
|
||||
id: 1
|
||||
public: "public"
|
||||
email: "public"
|
||||
secrets:
|
||||
card_number: "this is a secret"
|
||||
|
||||
@@ -46,9 +46,6 @@ describe "CheckoutCtrl", ->
|
||||
it "is disabled", ->
|
||||
expect(scope.enabled).toEqual false
|
||||
|
||||
it "binds order to local storage", ->
|
||||
expect(localStorage.getItem("order_#{Order.order.id}#{Order.order.user_id}")).toMatch Order.order.public
|
||||
|
||||
it "does not store secrets in local storage", ->
|
||||
keys = (localStorage.key(i) for i in [0..localStorage.length])
|
||||
for key in keys
|
||||
|
||||
@@ -5,11 +5,13 @@ describe 'Order service', ->
|
||||
Navigation = null
|
||||
flash = null
|
||||
storage = null
|
||||
scope = null
|
||||
|
||||
beforeEach ->
|
||||
orderData =
|
||||
id: 3102
|
||||
payment_method_id: null
|
||||
email: "test@test.com"
|
||||
bill_address:
|
||||
test: "foo"
|
||||
firstname: "Robert"
|
||||
@@ -35,10 +37,12 @@ describe 'Order service', ->
|
||||
angular.module('Darkswarm').value('order', orderData)
|
||||
module 'Darkswarm'
|
||||
|
||||
inject ($injector, _$httpBackend_, _storage_)->
|
||||
inject ($injector, _$httpBackend_, _storage_, $rootScope)->
|
||||
$httpBackend = _$httpBackend_
|
||||
storage = _storage_
|
||||
Order = $injector.get("Order")
|
||||
scope = $rootScope.$new()
|
||||
scope.Order = Order
|
||||
Navigation = $injector.get("Navigation")
|
||||
flash = $injector.get("flash")
|
||||
spyOn(Navigation, "go") # Stubbing out writes to window.location
|
||||
@@ -58,6 +62,18 @@ describe 'Order service', ->
|
||||
expect(storage.bind).toHaveBeenCalledWith({}, "Order.order.testy", {storeName: "#{prefix}_testy"})
|
||||
expect(storage.bind).toHaveBeenCalledWith({}, "Order.ship_address_same_as_billing", {storeName: "#{prefix}_sameasbilling", defaultValue: true})
|
||||
|
||||
it "binds order to local storage", ->
|
||||
Order.bindFieldsToLocalStorage(scope)
|
||||
prefix = "order_#{Order.order.id}#{Order.order.user_id}"
|
||||
expect(localStorage.getItem("#{prefix}_email")).toMatch "test@test.com"
|
||||
|
||||
it "does not store secrets in local storage", ->
|
||||
Order.secrets =
|
||||
card_number: "superfuckingsecret"
|
||||
Order.bindFieldsToLocalStorage(scope)
|
||||
keys = (localStorage.key(i) for i in [0..localStorage.length])
|
||||
for key in keys
|
||||
expect(localStorage.getItem(key)).not.toMatch Order.secrets.card_number
|
||||
|
||||
describe "with shipping method", ->
|
||||
beforeEach ->
|
||||
|
||||
Reference in New Issue
Block a user