|
1 | 1 | import { describe, it, expect, beforeEach, vi } from 'vitest'; |
2 | | -import { CancellationToken } from 'vscode-languageserver-protocol'; |
| 2 | +import { CancellationToken, RequestHandler } from 'vscode-languageserver-protocol'; |
| 3 | +import { TextDocument } from 'vscode-languageserver-textdocument'; |
3 | 4 | import { getEntityMap } from '../../../src/context/SectionContextBuilder'; |
| 5 | +import { Document } from '../../../src/document/Document'; |
4 | 6 | import { |
5 | 7 | getManagedResourceStackTemplateHandler, |
| 8 | + importResourceStateHandler, |
6 | 9 | removeResourceTypeHandler, |
7 | 10 | } from '../../../src/handlers/ResourceHandler'; |
| 11 | +import { |
| 12 | + ResourceStateParams, |
| 13 | + ResourceStatePurpose, |
| 14 | + ResourceStateResult, |
| 15 | +} from '../../../src/resourceState/ResourceStateTypes'; |
8 | 16 | import { GetStackTemplateParams } from '../../../src/stacks/StackRequestType'; |
9 | 17 | import { createMockComponents } from '../../utils/MockServerComponents'; |
10 | 18 |
|
@@ -156,3 +164,37 @@ describe('ResourceHandler - removeResourceTypeHandler', () => { |
156 | 164 | expect(() => handler(undefined as any)).toThrow(); |
157 | 165 | }); |
158 | 166 | }); |
| 167 | + |
| 168 | +describe('ResourceHandler - importResourceStateHandler', () => { |
| 169 | + let mockComponents: ReturnType<typeof createMockComponents>; |
| 170 | + let handler: RequestHandler<ResourceStateParams, ResourceStateResult, void>; |
| 171 | + |
| 172 | + beforeEach(() => { |
| 173 | + vi.clearAllMocks(); |
| 174 | + mockComponents = createMockComponents(); |
| 175 | + handler = importResourceStateHandler(mockComponents); |
| 176 | + }); |
| 177 | + |
| 178 | + it('should throw error if template file is not open', async () => { |
| 179 | + mockComponents.documentManager.get.returns( |
| 180 | + new Document(TextDocument.create('sample.yaml', 'yaml', 1, 'Hello:')), |
| 181 | + ); |
| 182 | + mockComponents.documentManager.isTemplate.resolves(false); |
| 183 | + |
| 184 | + await expect(async () => { |
| 185 | + await handler( |
| 186 | + { |
| 187 | + textDocument: { uri: 'docUri' }, |
| 188 | + resourceSelections: [ |
| 189 | + { |
| 190 | + resourceType: 'AWS::S3::Bucket', |
| 191 | + resourceIdentifiers: ['bucket1234'], |
| 192 | + }, |
| 193 | + ], |
| 194 | + purpose: ResourceStatePurpose.IMPORT, |
| 195 | + }, |
| 196 | + CancellationToken.None, |
| 197 | + ); |
| 198 | + }).rejects.toThrow('Must open CloudFormation template to import or clone resource state'); |
| 199 | + }); |
| 200 | +}); |
0 commit comments