|
| 1 | +// |
| 2 | +// Copyright © 2025 Hardcore Engineering Inc. |
| 3 | +// |
| 4 | +// Licensed under the Eclipse Public License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. You may |
| 6 | +// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | +// |
| 15 | + |
| 16 | +import { getEmailMessageIdFromHulyId, getHulyIdFromEmailMessageId, isHulyEmailMessageId } from '../utils' |
| 17 | + |
| 18 | +describe('Email Message ID Conversion', () => { |
| 19 | + describe('getEmailMessageIdFromHulyId', () => { |
| 20 | + it('should convert Huly ID to email Message-ID format', () => { |
| 21 | + const hulyId = 'msg_123456789abcdef' |
| 22 | + |
| 23 | + const result = getEmailMessageIdFromHulyId(hulyId, email) |
| 24 | + expect(result).toBe('<[email protected]>') |
| 25 | + }) |
| 26 | + |
| 27 | + it('should handle different domains', () => { |
| 28 | + const hulyId = 'huly_message_001' |
| 29 | + |
| 30 | + const result = getEmailMessageIdFromHulyId(hulyId, email) |
| 31 | + expect(result).toBe('<[email protected]>') |
| 32 | + }) |
| 33 | + |
| 34 | + it('should handle subdomain emails', () => { |
| 35 | + const hulyId = 'test_msg' |
| 36 | + |
| 37 | + const result = getEmailMessageIdFromHulyId(hulyId, email) |
| 38 | + expect(result).toBe('<[email protected]>') |
| 39 | + }) |
| 40 | + |
| 41 | + it('should handle complex Huly IDs', () => { |
| 42 | + const hulyId = 'channel_123_thread_456_msg_789' |
| 43 | + |
| 44 | + const result = getEmailMessageIdFromHulyId(hulyId, email) |
| 45 | + expect(result).toBe('<[email protected]>') |
| 46 | + }) |
| 47 | + |
| 48 | + it('should throw error for invalid email', () => { |
| 49 | + const hulyId = 'msg_123' |
| 50 | + const invalidEmail = 'not-an-email' |
| 51 | + expect(() => getEmailMessageIdFromHulyId(hulyId, invalidEmail)).toThrow('Invalid email address') |
| 52 | + }) |
| 53 | + }) |
| 54 | + |
| 55 | + describe('getHulyIdFromEmailMessageId', () => { |
| 56 | + it('should extract Huly ID from email Message-ID', () => { |
| 57 | + const messageId = '<[email protected]>' |
| 58 | + |
| 59 | + const result = getHulyIdFromEmailMessageId(messageId, email) |
| 60 | + expect(result).toBe('msg_123456789abcdef') |
| 61 | + }) |
| 62 | + |
| 63 | + it('should handle Message-ID without angle brackets', () => { |
| 64 | + const messageId = '[email protected]' |
| 65 | + |
| 66 | + const result = getHulyIdFromEmailMessageId(messageId, email) |
| 67 | + expect(result).toBe('msg_123456789abcdef') |
| 68 | + }) |
| 69 | + |
| 70 | + it('should return undefined for non-matching domain', () => { |
| 71 | + const messageId = '<[email protected]>' |
| 72 | + |
| 73 | + const result = getHulyIdFromEmailMessageId(messageId, email) |
| 74 | + expect(result).toBeUndefined() |
| 75 | + }) |
| 76 | + |
| 77 | + it('should handle complex domains', () => { |
| 78 | + const messageId = '<[email protected]>' |
| 79 | + |
| 80 | + const result = getHulyIdFromEmailMessageId(messageId, email) |
| 81 | + expect(result).toBe('channel_123_thread_456') |
| 82 | + }) |
| 83 | + |
| 84 | + it('should handle empty Huly ID part', () => { |
| 85 | + const messageId = '<@example.com>' |
| 86 | + |
| 87 | + const result = getHulyIdFromEmailMessageId(messageId, email) |
| 88 | + expect(result).toBe('') |
| 89 | + }) |
| 90 | + |
| 91 | + it('should return undefined for standard email Message-IDs', () => { |
| 92 | + const messageId = '<[email protected]>' |
| 93 | + |
| 94 | + const result = getHulyIdFromEmailMessageId(messageId, email) |
| 95 | + expect(result).toBeUndefined() |
| 96 | + }) |
| 97 | + |
| 98 | + it('should handle multiple @ symbols in Message-ID', () => { |
| 99 | + const messageId = '<msg@[email protected]>' |
| 100 | + |
| 101 | + const result = getHulyIdFromEmailMessageId(messageId, email) |
| 102 | + expect(result).toBe('msg@test') |
| 103 | + }) |
| 104 | + |
| 105 | + it('should throw error for invalid email', () => { |
| 106 | + const messageId = '<[email protected]>' |
| 107 | + const invalidEmail = 'not-an-email' |
| 108 | + expect(() => getHulyIdFromEmailMessageId(messageId, invalidEmail)).toThrow('Invalid email address') |
| 109 | + }) |
| 110 | + }) |
| 111 | + |
| 112 | + describe('isHulyEmailMessageId', () => { |
| 113 | + it('should return true for valid Huly Message-ID', () => { |
| 114 | + const messageId = '<[email protected]>' |
| 115 | + |
| 116 | + const result = isHulyEmailMessageId(messageId, email) |
| 117 | + expect(result).toBe(true) |
| 118 | + }) |
| 119 | + |
| 120 | + it('should return false for non-matching domain', () => { |
| 121 | + const messageId = '<[email protected]>' |
| 122 | + |
| 123 | + const result = isHulyEmailMessageId(messageId, email) |
| 124 | + expect(result).toBe(false) |
| 125 | + }) |
| 126 | + |
| 127 | + it('should return false for standard email Message-IDs', () => { |
| 128 | + const messageId = '<[email protected]>' |
| 129 | + |
| 130 | + const result = isHulyEmailMessageId(messageId, email) |
| 131 | + expect(result).toBe(false) |
| 132 | + }) |
| 133 | + |
| 134 | + it('should return true for Message-ID without angle brackets', () => { |
| 135 | + const messageId = '[email protected]' |
| 136 | + |
| 137 | + const result = isHulyEmailMessageId(messageId, email) |
| 138 | + expect(result).toBe(true) |
| 139 | + }) |
| 140 | + }) |
| 141 | + |
| 142 | + describe('Round-trip conversion', () => { |
| 143 | + it('should preserve Huly ID through round-trip conversion', () => { |
| 144 | + const originalHulyId = 'msg_123456789abcdef' |
| 145 | + |
| 146 | + |
| 147 | + const messageId = getEmailMessageIdFromHulyId(originalHulyId, email) |
| 148 | + const extractedHulyId = getHulyIdFromEmailMessageId(messageId, email) |
| 149 | + |
| 150 | + expect(extractedHulyId).toBe(originalHulyId) |
| 151 | + }) |
| 152 | + |
| 153 | + it('should work with complex Huly IDs', () => { |
| 154 | + const originalHulyId = 'channel_abc123_thread_def456_msg_789xyz' |
| 155 | + |
| 156 | + |
| 157 | + const messageId = getEmailMessageIdFromHulyId(originalHulyId, email) |
| 158 | + const extractedHulyId = getHulyIdFromEmailMessageId(messageId, email) |
| 159 | + |
| 160 | + expect(extractedHulyId).toBe(originalHulyId) |
| 161 | + }) |
| 162 | + |
| 163 | + it('should work with subdomain emails', () => { |
| 164 | + const originalHulyId = 'notification_001' |
| 165 | + |
| 166 | + |
| 167 | + const messageId = getEmailMessageIdFromHulyId(originalHulyId, email) |
| 168 | + const extractedHulyId = getHulyIdFromEmailMessageId(messageId, email) |
| 169 | + |
| 170 | + expect(extractedHulyId).toBe(originalHulyId) |
| 171 | + }) |
| 172 | + }) |
| 173 | + |
| 174 | + describe('Edge cases', () => { |
| 175 | + it('should handle Huly ID with special characters', () => { |
| 176 | + const hulyId = 'msg-123_test.001' |
| 177 | + |
| 178 | + |
| 179 | + const messageId = getEmailMessageIdFromHulyId(hulyId, email) |
| 180 | + expect(messageId).toBe('<[email protected]>') |
| 181 | + |
| 182 | + const extractedHulyId = getHulyIdFromEmailMessageId(messageId, email) |
| 183 | + expect(extractedHulyId).toBe(hulyId) |
| 184 | + }) |
| 185 | + |
| 186 | + it('should handle very long Huly IDs', () => { |
| 187 | + const hulyId = 'very_long_huly_id_with_many_segments_and_characters_123456789abcdef' |
| 188 | + |
| 189 | + |
| 190 | + const messageId = getEmailMessageIdFromHulyId(hulyId, email) |
| 191 | + const extractedHulyId = getHulyIdFromEmailMessageId(messageId, email) |
| 192 | + |
| 193 | + expect(extractedHulyId).toBe(hulyId) |
| 194 | + }) |
| 195 | + |
| 196 | + it('should handle empty Huly ID', () => { |
| 197 | + const hulyId = '' |
| 198 | + |
| 199 | + |
| 200 | + const messageId = getEmailMessageIdFromHulyId(hulyId, email) |
| 201 | + expect(messageId).toBe('<@example.com>') |
| 202 | + |
| 203 | + const extractedHulyId = getHulyIdFromEmailMessageId(messageId, email) |
| 204 | + expect(extractedHulyId).toBe('') |
| 205 | + }) |
| 206 | + }) |
| 207 | +}) |
0 commit comments