|
| 1 | +/* |
| 2 | +Copyright 2018 New Vector Ltd |
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. |
| 5 | +You may obtain a copy of the License at |
| 6 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +Unless required by applicable law or agreed to in writing, software |
| 8 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +See the License for the specific language governing permissions and |
| 11 | +limitations under the License. |
| 12 | +*/ |
| 13 | + |
| 14 | +import expect from 'expect'; |
| 15 | +import {phasedRollOutExpiredForUser} from '../src/PhasedRollOut'; |
| 16 | + |
| 17 | +const OFFSET = 6000000; |
| 18 | +// phasedRollOutExpiredForUser enables users in bucks of 1 minute |
| 19 | +const MS_IN_MINUTE = 60 * 1000; |
| 20 | + |
| 21 | +describe('PhasedRollOut', function() { |
| 22 | + it('should return true if phased rollout is not configured', function() { |
| 23 | + expect(phasedRollOutExpiredForUser("@user:hs", "feature_test", 0, null)).toBeTruthy(); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should return true if phased rollout feature is not configured', function() { |
| 27 | + expect(phasedRollOutExpiredForUser("@user:hs", "feature_test", 0, { |
| 28 | + "feature_other": {offset: 0, period: 0}, |
| 29 | + })).toBeTruthy(); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should return false if phased rollout for feature is misconfigured', function() { |
| 33 | + expect(phasedRollOutExpiredForUser("@user:hs", "feature_test", 0, { |
| 34 | + "feature_test": {}, |
| 35 | + })).toBeFalsy(); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should return false if phased rollout hasn't started yet", function() { |
| 39 | + expect(phasedRollOutExpiredForUser("@user:hs", "feature_test", 5000000, { |
| 40 | + "feature_test": {offset: OFFSET, period: MS_IN_MINUTE}, |
| 41 | + })).toBeFalsy(); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should start to return true in bucket 2/10 for '@user:hs'", function() { |
| 45 | + expect(phasedRollOutExpiredForUser("@user:hs", "feature_test", |
| 46 | + OFFSET + (MS_IN_MINUTE * 2) - 1, { |
| 47 | + "feature_test": {offset: OFFSET, period: MS_IN_MINUTE * 10}, |
| 48 | + })).toBeFalsy(); |
| 49 | + expect(phasedRollOutExpiredForUser("@user:hs", "feature_test", |
| 50 | + OFFSET + (MS_IN_MINUTE * 2), { |
| 51 | + "feature_test": {offset: OFFSET, period: MS_IN_MINUTE * 10}, |
| 52 | + })).toBeTruthy(); |
| 53 | + }); |
| 54 | + |
| 55 | + it("should start to return true in bucket 4/10 for 'alice@other-hs'", function() { |
| 56 | + expect(phasedRollOutExpiredForUser("alice@other-hs", "feature_test", |
| 57 | + OFFSET + (MS_IN_MINUTE * 4) - 1, { |
| 58 | + "feature_test": {offset: OFFSET, period: MS_IN_MINUTE * 10}, |
| 59 | + })).toBeFalsy(); |
| 60 | + expect(phasedRollOutExpiredForUser("alice@other-hs", "feature_test", |
| 61 | + OFFSET + (MS_IN_MINUTE * 4), { |
| 62 | + "feature_test": {offset: OFFSET, period: MS_IN_MINUTE * 10}, |
| 63 | + })).toBeTruthy(); |
| 64 | + }); |
| 65 | + |
| 66 | + it("should return true after complete rollout period'", function() { |
| 67 | + expect(phasedRollOutExpiredForUser("user:hs", "feature_test", |
| 68 | + OFFSET + (MS_IN_MINUTE * 20), { |
| 69 | + "feature_test": {offset: OFFSET, period: MS_IN_MINUTE * 10}, |
| 70 | + })).toBeTruthy(); |
| 71 | + }); |
| 72 | +}); |
0 commit comments