summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2017-11-23 15:53:28 +0100
committerAndrej Mihajlov <and@mullvad.net>2017-12-06 11:48:39 +0100
commitadd9f88c0070514c0de8b3ef0f37e8f7a8726222 (patch)
tree8dd1a73f93aac194790e6b008d96c1e459b05ff1 /test
parent6cee4adfe1b314ece9773697b89370e964c5279e (diff)
downloadmullvadvpn-add9f88c0070514c0de8b3ef0f37e8f7a8726222.tar.xz
mullvadvpn-add9f88c0070514c0de8b3ef0f37e8f7a8726222.zip
Add relay constraint builder and basic tests
Diffstat (limited to 'test')
-rw-r--r--test/relay-settings-builder.spec.js151
1 files changed, 151 insertions, 0 deletions
diff --git a/test/relay-settings-builder.spec.js b/test/relay-settings-builder.spec.js
new file mode 100644
index 0000000000..3f27d2df23
--- /dev/null
+++ b/test/relay-settings-builder.spec.js
@@ -0,0 +1,151 @@
+// @flow
+
+import { expect } from 'chai';
+import RelaySettingsBuilder from '../app/lib/relay-settings-builder';
+
+describe('Relay settings builder', () => {
+
+ it('should set location to any', () => {
+ expect(
+ RelaySettingsBuilder.normal()
+ .location
+ .any()
+ .build()
+ ).to.deep.equal({
+ normal: {
+ location: 'any'
+ }
+ });
+ });
+
+ it('should bound location to city', () => {
+ expect(
+ RelaySettingsBuilder.normal()
+ .location.city('se', 'mma').build()
+ ).to.deep.equal({
+ normal: {
+ location: {
+ only: {
+ city: ['se', 'mma']
+ }
+ }
+ }
+ });
+ });
+
+ it('should bound location to country', () => {
+ expect(
+ RelaySettingsBuilder.normal()
+ .location.country('se').build()
+ ).to.deep.equal({
+ normal: {
+ location: {
+ only: { country: 'se' }
+ }
+ }
+ });
+ });
+
+ it('should set openvpn settings to any', () => {
+ expect(
+ RelaySettingsBuilder.normal()
+ .tunnel.openvpn(openvpn => {
+ openvpn.port.any()
+ .protocol.any();
+ })
+ .build()
+ ).to.deep.equal({
+ normal: {
+ tunnel: {
+ only: {
+ openvpn: {
+ port: 'any',
+ protocol: 'any'
+ }
+ }
+ }
+ }
+ });
+ });
+
+ it('should set openvpn settings to exact values', () => {
+ expect(
+ RelaySettingsBuilder.normal()
+ .tunnel.openvpn(openvpn => {
+ openvpn.port.exact(80)
+ .protocol.exact('tcp');
+ })
+ .build()
+ ).to.deep.equal({
+ normal: {
+ tunnel: {
+ only: {
+ openvpn: {
+ port: { only: 80 },
+ protocol: { only: 'tcp' }
+ }
+ }
+ }
+ }
+ });
+ });
+
+ it('should set location from raw RelayLocation', () => {
+ expect(
+ RelaySettingsBuilder.normal()
+ .location.fromRaw('any')
+ .build()
+ ).to.deep.equal({
+ normal: {
+ location: 'any'
+ }
+ });
+
+ expect(
+ RelaySettingsBuilder.normal()
+ .location.fromRaw({ country: 'se'})
+ .build()
+ ).to.deep.equal({
+ normal: {
+ location: {
+ only: { country: 'se' }
+ }
+ }
+ });
+
+ expect(
+ RelaySettingsBuilder.normal()
+ .location.fromRaw({ city: ['se', 'mma']})
+ .build()
+ ).to.deep.equal({
+ normal: {
+ location: {
+ only: { city: ['se', 'mma'] }
+ }
+ }
+ });
+ });
+
+ it('should set custom endpoint settings', () => {
+ expect(
+ RelaySettingsBuilder.custom()
+ .host('se2.mullvad.net')
+ .tunnel.openvpn((openvpn) => {
+ openvpn.port(80)
+ .protocol('tcp');
+ })
+ .build()
+ ).to.deep.equal({
+ custom_tunnel_endpoint: {
+ host: 'se2.mullvad.net',
+ tunnel: {
+ openvpn: {
+ port: 80,
+ protocol: 'tcp'
+ }
+ }
+ }
+ });
+ });
+
+}); \ No newline at end of file