Skip to content

Commit 77fac56

Browse files
committed
refactor(series/info.html): allow to stub different responses based on a URL.
Relate to #1280
1 parent cd9f824 commit 77fac56

File tree

1 file changed

+35
-26
lines changed
  • src/main/webapp/WEB-INF/views/series

1 file changed

+35
-26
lines changed

Diff for: src/main/webapp/WEB-INF/views/series/info.html

+35-26
Original file line numberDiff line numberDiff line change
@@ -794,36 +794,42 @@ <h5 th:text="#{t_add_info_who_selling_series}">Add info about selling/buying thi
794794
/*[- */
795795
var responseCount = 0;
796796
window.axios = {
797-
post: function() {
797+
post: function(url) {
798798
var possibleOutcomes = [ 'failOnForm', 'failOnField', 'success' ];
799799
var outcome = possibleOutcomes[responseCount % possibleOutcomes.length];
800-
var stubResponse;
801-
802-
if (outcome === 'failOnForm') {
803-
stubResponse = {
804-
status: 500,
805-
statusText: 'Fake Server Error'
806-
};
807-
808-
} else if (outcome === 'failOnField') {
809-
stubResponse = {
810-
status: 400,
811-
data: {
812-
"fieldErrors": {
813-
"url": [ "Invalid value" ]
800+
var possibleResponses = {
801+
'/series/sales/import': {
802+
'failOnField': {
803+
status: 400,
804+
data: {
805+
'fieldErrors': {
806+
'url': [ 'Invalid value' ]
807+
}
808+
}
809+
},
810+
'success': {
811+
status: 200,
812+
data: {
813+
'sellerId': 3,
814+
'price': 3.5,
815+
'currency' : 'USD'
814816
}
815817
}
816-
};
818+
}
819+
};
820+
var stubResponse;
817821

818-
} else if (outcome === 'success') {
819-
stubResponse = {
820-
status: 200,
821-
data: {
822-
"sellerId": 3,
823-
"price": 3.5,
824-
"currency" : "USD"
825-
}
826-
};
822+
switch (outcome) {
823+
case 'success':
824+
case 'failOnField':
825+
stubResponse = possibleResponses[url][outcome];
826+
break;
827+
case 'failOnForm':
828+
default:
829+
stubResponse = {
830+
status: 500,
831+
statusText: 'Fake Server Error'
832+
};
827833
}
828834

829835
responseCount++;
@@ -862,7 +868,10 @@ <h5 th:text="#{t_add_info_who_selling_series}">Add info about selling/buying thi
862868
+]*/
863869

864870
/*[- */
865-
var importFormProps = { 'l10n': {} };
871+
var importFormProps = {
872+
'url': '/series/sales/import',
873+
'l10n': {}
874+
};
866875
/* -]*/
867876

868877
renderComponent(SeriesSaleImportForm, importFormProps, 'importSeriesSaleForm');

0 commit comments

Comments
 (0)