remove legacy checkout tests

This commit is contained in:
Mohamed ABDELLANI
2023-06-01 05:51:32 +01:00
committed by Filipe
parent 907c65d98c
commit bd0e7cdfc8
24 changed files with 216 additions and 850 deletions

View File

@@ -1,24 +0,0 @@
describe "AccordionCtrl", ->
ctrl = null
scope = null
CurrentHubMock =
hub:
id: 1
beforeEach ->
module "Darkswarm"
module ($provide)->
$provide.value "CurrentHub", CurrentHubMock
null
inject ($controller, $rootScope) ->
scope = $rootScope.$new()
scope.order =
id: 129
ctrl = $controller 'AccordionCtrl', {$scope: scope}
it "defaults the details accordion to visible", ->
expect(scope.accordion.details).toEqual true
it "changes accordion", ->
scope.show "shipping"
expect(scope.accordion["shipping"]).toEqual true

View File

@@ -1,100 +0,0 @@
describe "CheckoutCtrl", ->
ctrl = null
scope = null
Checkout = null
CurrentUser = null
CurrentHubMock =
hub:
id: 1
localStorageService = null
beforeEach ->
module("Darkswarm")
angular.module('Darkswarm').value('user', {})
angular.module('Darkswarm').value('currentHub', {id: 1})
module ($provide)->
$provide.value "CurrentHub", CurrentHubMock
null
Checkout =
purchase: ->
submit: ->
navigate: ->
bindFieldsToLocalStorage: ->
order:
id: 1
email: "public"
user_id: 1
bill_address: 'bill_address'
ship_address: 'ship address'
secrets:
card_number: "this is a secret"
describe "with user", ->
beforeEach ->
inject ($controller, $rootScope, _localStorageService_) ->
localStorageService = _localStorageService_
spyOn(localStorageService, "bind").and.callThrough()
scope = $rootScope.$new()
CurrentUser = { id: 1 }
ctrl = $controller 'CheckoutCtrl', {$scope: scope, Checkout: Checkout, CurrentUser: CurrentUser }
describe "submitting", ->
event =
preventDefault: ->
beforeEach ->
spyOn(Checkout, "purchase")
scope.submitted = false
it "delegates to the service when valid", ->
scope.purchase(event, {$valid: true})
expect(Checkout.purchase).toHaveBeenCalled()
expect(scope.submitted).toBe(true)
it "does nothing when invalid", ->
scope.purchase(event, {$valid: false})
expect(Checkout.purchase).not.toHaveBeenCalled()
expect(scope.submitted).toBe(true)
it "is enabled", ->
expect(scope.enabled).toEqual true
describe "Local storage", ->
it "binds to localStorage when given a scope", inject ($timeout) ->
prefix = "order_#{scope.order.id}#{CurrentUser.id or ""}#{CurrentHubMock.hub.id}"
field = scope.fieldsToBind[0]
expect(localStorageService.bind).toHaveBeenCalledWith(scope, "Checkout.order.#{field}", Checkout.order[field], "#{prefix}_#{field}")
expect(localStorageService.bind).toHaveBeenCalledWith(scope, "Checkout.ship_address_same_as_billing", true, "#{prefix}_sameasbilling")
expect(localStorageService.bind).toHaveBeenCalledWith(scope, "Checkout.default_bill_address", false, "#{prefix}_defaultasbilladdress")
expect(localStorageService.bind).toHaveBeenCalledWith(scope, "Checkout.default_ship_address", false, "#{prefix}_defaultasshipaddress")
it "it can retrieve data from localstorage", ->
prefix = "order_#{scope.order.id}#{CurrentUser.id or ""}#{CurrentHubMock.hub.id}"
scope.$digest()
expect(localStorage.getItem("ls.#{prefix}_email")).toMatch "public"
it "does not store secrets in local storage", ->
Checkout.secrets =
card_number: "superfuckingsecret"
scope.$digest()
keys = (localStorage.key(i) for i in [0..localStorage.length])
for key in keys
expect(localStorage.getItem(key)).not.toMatch Checkout.secrets.card_number
describe "without user", ->
beforeEach ->
inject ($controller, $rootScope) ->
scope = $rootScope.$new()
ctrl = $controller 'CheckoutCtrl', {$scope: scope, Checkout: Checkout, CurrentUser: {}}
it "is disabled", ->
expect(scope.enabled).toEqual false
it "does not store secrets in local storage", ->
Checkout.secrets =
card_number: "superfuckingsecret"
scope.$digest()
keys = (localStorage.key(i) for i in [0..localStorage.length])
for key in keys
expect(localStorage.getItem(key)).not.toMatch Checkout.secrets.card_number

View File

@@ -1,37 +0,0 @@
describe "DetailsCtrl", ->
ctrl = null
scope = null
order = null
CurrentUser = null
beforeEach ->
module("Darkswarm")
inject ($controller, $rootScope) ->
scope = $rootScope.$new()
CurrentUser = { id: 1 }
ctrl = $controller 'DetailsCtrl', { $scope: scope, CurrentUser: CurrentUser }
it "finds a field by path", ->
scope.details =
path: "test"
expect(scope.field('path')).toEqual "test"
it "tests validity", ->
scope.details =
path:
$dirty: true
$invalid: true
expect(scope.fieldValid('path')).toEqual false
it "returns errors by path", ->
scope.Order =
errors: ->
scope.details =
path:
$error:
email: true
required: true
expect(scope.fieldErrors('path')).toEqual ["must be email address", "can't be blank"].join ", "

View File

@@ -1,17 +0,0 @@
describe "PaymentCtrl", ->
ctrl = null
scope = null
card1 = { id: 1, is_default: false }
card2 = { id: 3, is_default: true }
cards = [card1, card2]
beforeEach ->
module("Darkswarm")
angular.module('Darkswarm').value('savedCreditCards', cards)
inject ($controller, $rootScope) ->
scope = $rootScope.$new()
scope.secrets = {}
ctrl = $controller 'PaymentCtrl', {$scope: scope}
it "sets the default card id as the selected_card", ->
expect(scope.secrets.selected_card).toEqual card2.id

View File

@@ -1,164 +0,0 @@
describe "ShopVariantCtrl", ->
ctrl = null
scope = null
CartMock = null
beforeEach ->
module 'Darkswarm'
inject ($rootScope, $controller, $modal)->
scope = $rootScope.$new()
scope.$watchGroup = ->
scope.variant = {
on_demand: true
product: {group_buy: true}
line_item: {
quantity: undefined
max_quantity: undefined
}
}
CartMock =
adjust: ->
true
ctrl = $controller 'ShopVariantCtrl', {$scope: scope, $modal: $modal, Cart: CartMock, Shopfront: {}}
it "initializes the quantity for shop display", ->
expect(scope.variant.line_item.quantity).toEqual 0
it "adds an item to the cart", ->
scope.add 1
expect(scope.variant.line_item.quantity).toEqual 1
it "adds to the existing quantity", ->
scope.add 1
scope.add 5
expect(scope.variant.line_item.quantity).toEqual 6
it "adds to an invalid quantity", ->
scope.$apply ->
scope.variant.line_item.quantity = -5
scope.add 1
expect(scope.variant.line_item.quantity).toEqual 1
it "adds to an undefined quantity", ->
scope.$apply ->
scope.variant.line_item.quantity = undefined
scope.add 1
expect(scope.variant.line_item.quantity).toEqual 1
it "adds to the max quantity", ->
scope.addMax 5
expect(scope.variant.line_item.quantity).toEqual 0
expect(scope.variant.line_item.max_quantity).toEqual 5
it "adds to an undefined max quantity", ->
scope.variant.line_item.quantity = 3
scope.variant.line_item.max_quantity = undefined
scope.addMax 1
expect(scope.variant.line_item.max_quantity).toEqual 4
it "adds to the max quantity to be at least min quantity", ->
scope.$apply ->
scope.variant.line_item.max_quantity = 2
scope.$apply ->
scope.add 3
expect(scope.variant.line_item.quantity).toEqual 3
expect(scope.variant.line_item.max_quantity).toEqual 3
it "decreases the min quantity to not exceed max quantity", ->
scope.$apply ->
scope.variant.line_item.quantity = 3
scope.variant.line_item.max_quantity = 5
scope.$apply ->
scope.addMax -3
expect(scope.variant.line_item.quantity).toEqual 2
expect(scope.variant.line_item.max_quantity).toEqual 2
it "caps at the available quantity", ->
scope.$apply ->
scope.variant.on_demand = false
scope.variant.on_hand = 3
scope.variant.line_item.quantity = 5
scope.variant.line_item.max_quantity = 7
expect(scope.variant.line_item.quantity).toEqual 3
expect(scope.variant.line_item.max_quantity).toEqual 3
it "allows adding when variant is on demand", ->
expect(scope.canAdd(5000)).toEqual true
it "denies adding if variant is out of stock", ->
scope.variant.on_demand = false
scope.variant.on_hand = 0
expect(scope.canAdd(1)).toEqual false
it "denies adding if stock is limitted", ->
scope.variant.on_demand = false
scope.variant.on_hand = 5
expect(scope.canAdd(4)).toEqual true
expect(scope.canAdd(5)).toEqual true
expect(scope.canAdd(6)).toEqual false
scope.add 3
expect(scope.canAdd(2)).toEqual true
expect(scope.canAdd(3)).toEqual false
it "denies adding if quantity is too high", ->
scope.variant.on_demand = false
scope.variant.on_hand = 5
scope.variant.line_item.quantity = 7
scope.variant.line_item.max_quantity = 7
expect(scope.canAdd(1)).toEqual false
expect(scope.canAddMax(1)).toEqual false
it "allows decrease when quantity is too high", ->
scope.variant.on_demand = false
scope.variant.on_hand = 5
scope.variant.line_item.quantity = 7
scope.variant.line_item.max_quantity = 7
expect(scope.canAdd(-1)).toEqual true
expect(scope.canAddMax(-1)).toEqual true
it "allows increase when quantity is negative", ->
scope.variant.on_demand = false
scope.variant.on_hand = 5
scope.variant.line_item.quantity = -3
scope.variant.line_item.max_quantity = -3
expect(scope.canAdd(1)).toEqual true
expect(scope.canAddMax(1)).toEqual false
scope.variant.line_item.quantity = 1
expect(scope.canAddMax(1)).toEqual true
it "denies decrease when quantity is negative", ->
scope.variant.on_demand = false
scope.variant.on_hand = 5
scope.variant.line_item.quantity = -3
scope.variant.line_item.max_quantity = -3
expect(scope.canAdd(-1)).toEqual false
expect(scope.canAddMax(-1)).toEqual false
it "denies declaring max quantity before item is in cart", ->
expect(scope.canAddMax(1)).toEqual false
it "allows declaring max quantity when item is in cart", ->
scope.add 1
expect(scope.canAddMax(1)).toEqual true
it "denies adding if stock is limitted", ->
scope.variant.on_demand = false
scope.variant.on_hand = 5
scope.variant.line_item.quantity = 1
scope.variant.line_item.max_quantity = 1
expect(scope.canAddMax(3)).toEqual true
expect(scope.canAddMax(4)).toEqual true
expect(scope.canAddMax(5)).toEqual false
expect(scope.canAddMax(6)).toEqual false