Last active
August 29, 2015 14:17
-
-
Save steverobbins/302bc4fbb91b02f7b810 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var settings = { | |
exclude: ["US"], | |
regionselector: "example.com/regionselector", | |
homepages: { | |
"US": "example.com", | |
"DE": "example.com/de", | |
"FR": "example.com/fr", | |
"EU": "example.com/eu" | |
} | |
}, | |
tests = { | |
test00: { | |
"geoip_detected": "US", | |
"cookied_to": null, | |
"landed_on": "US", | |
"result": "no redirect" | |
}, | |
test01: { | |
"geoip_detected": "US", | |
"cookied_to": null, | |
"landed_on": "FR", | |
"result": "no redirect" | |
}, | |
test02: { | |
"geoip_detected": "DE", | |
"cookied_to": "DE", | |
"landed_on": "US", | |
"result": "redirect to cookied home" | |
}, | |
test03: { | |
"geoip_detected": "FR", | |
"cookied_to": "FR", | |
"landed_on": "US", | |
"result": "redirect to cookied home" | |
}, | |
test04: { | |
"geoip_detected": "FR", | |
"cookied_to": null, | |
"landed_on": "FR", | |
"result": "no redirect" | |
}, | |
test05: { | |
"geoip_detected": "FR", | |
"cookied_to": null, | |
"landed_on": "US", | |
"result": "redirect to region selector" | |
}, | |
test06: { | |
"geoip_detected": null, | |
"cookied_to": null, | |
"landed_on": "EU", | |
"result": "redirect to region selector" | |
}, | |
test07: { | |
"geoip_detected": "US", | |
"cookied_to": "FR", | |
"landed_on": "US", | |
"result": "redirect to cookied home" | |
}, | |
test08: { | |
"geoip_detected": "FR", | |
"cookied_to": "FR", | |
"landed_on": "FR", | |
"result": "no redirect" | |
}, | |
test09: { | |
"geoip_detected": null, | |
"cookied_to": "FR", | |
"landed_on": "FR", | |
"result": "no redirect" | |
}, | |
test10: { | |
"geoip_detected": null, | |
"cookied_to": "EU", | |
"landed_on": "FR", | |
"result": "redirect to cookied home" | |
}, | |
test11: { | |
"geoip_detected": null, | |
"cookied_to": null, | |
"landed_on": null, | |
"result": "no redirect" | |
}, | |
test12: { | |
"geoip_detected": null, | |
"cookied_to": "EU", | |
"landed_on": null, | |
"result": "redirect to cookied home" | |
}, | |
test13: { | |
"geoip_detected": "US", | |
"cookied_to": "EU", | |
"landed_on": null, | |
"result": "no redirect" | |
}, | |
test14: { | |
"geoip_detected": "EU", | |
"cookied_to": "EU", | |
"landed_on": null, | |
"result": "no redirect" | |
}, | |
test15: { | |
"geoip_detected": "FR", | |
"cookied_to": "EU", | |
"landed_on": "EU", | |
"result": "no redirect" | |
}, | |
test16: { | |
"geoip_detected": "FR", | |
"cookied_to": null, | |
"landed_on": null, | |
"result": "no redirect" | |
} | |
}; | |
function validate(test) { | |
if (test.geoip_detected && test.cookied_to != test.landed_on) { | |
if (test.cookied_to) { | |
if (test.landed_on) { | |
return "redirect to cookied home"; | |
} | |
} else if (test.geoip_detected != test.landed_on && settings.exclude.indexOf(test.geoip_detected) == -1) { | |
return "redirect to region selector"; | |
} | |
} else { | |
if (test.cookied_to || !test.landed_on && test.cookied_to !== false) { | |
if (test.cookied_to != test.landed_on) { | |
return "redirect to cookied home"; | |
} | |
} else if (test.landed_on) { | |
return "redirect to region selector"; | |
} | |
} | |
return "no redirect"; | |
} | |
for (var testName in tests) { | |
var test = tests[testName], | |
result = validate(test); | |
if (test.result && test.result != result) { | |
document.write(testName + " failed! Expected '" + test.result + "' but got '" + result + "'<br />"); | |
} else { | |
document.write(testName + " passed<br />"); | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment