|
| 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +/* eslint-disable unused-imports/no-unused-vars */ |
| 5 | + |
| 6 | +import { StorageAccessLevel } from '@aws-amplify/core'; |
| 7 | + |
| 8 | +import { |
| 9 | + ListAllInput, |
| 10 | + ListAllOutput, |
| 11 | + ListAllWithPathInput, |
| 12 | + ListAllWithPathOutput, |
| 13 | + ListOutputItem, |
| 14 | + ListOutputItemWithPath, |
| 15 | + ListPaginateInput, |
| 16 | + ListPaginateOutput, |
| 17 | + ListPaginateWithPathInput, |
| 18 | + ListPaginateWithPathOutput, |
| 19 | +} from '../../../../src/providers/s3/types'; |
| 20 | +import { StorageSubpathStrategy } from '../../../../src/types'; |
| 21 | + |
| 22 | +import { Equal, Expect } from './utils'; |
| 23 | + |
| 24 | +interface Input { |
| 25 | + targetIdentityId?: string; |
| 26 | + prefix?: string; |
| 27 | + path: string; |
| 28 | + subpathStrategy?: StorageSubpathStrategy; |
| 29 | + nextToken: string; |
| 30 | + pageSize: number; |
| 31 | + useAccelerateEndpoint: boolean; |
| 32 | + accessLevel: StorageAccessLevel; |
| 33 | + listAll: boolean; |
| 34 | +} |
| 35 | + |
| 36 | +interface Output { |
| 37 | + listOutputItems: ListOutputItem[]; |
| 38 | + listOutputItemsWithPath: ListOutputItemWithPath[]; |
| 39 | + excludedSubpaths: string[]; |
| 40 | + nextToken: string; |
| 41 | +} |
| 42 | + |
| 43 | +describe('List API input types', () => { |
| 44 | + test('should compile', () => { |
| 45 | + function handleTest({ |
| 46 | + targetIdentityId, |
| 47 | + prefix, |
| 48 | + path, |
| 49 | + subpathStrategy, |
| 50 | + nextToken, |
| 51 | + pageSize, |
| 52 | + useAccelerateEndpoint, |
| 53 | + accessLevel, |
| 54 | + }: Input) { |
| 55 | + const listPaginateInput: ListPaginateInput = { |
| 56 | + prefix, |
| 57 | + options: { |
| 58 | + accessLevel: 'protected', |
| 59 | + targetIdentityId, |
| 60 | + // @ts-expect-error subpathStrategy is not part of this input |
| 61 | + subpathStrategy, |
| 62 | + }, |
| 63 | + }; |
| 64 | + |
| 65 | + const listAllInput: ListAllInput = { |
| 66 | + prefix, |
| 67 | + options: { |
| 68 | + listAll: true, |
| 69 | + accessLevel: 'protected', |
| 70 | + targetIdentityId, |
| 71 | + // @ts-expect-error subpathStrategy is not part of this input |
| 72 | + subpathStrategy, |
| 73 | + }, |
| 74 | + }; |
| 75 | + |
| 76 | + const listPaginateWithPathInput: ListPaginateWithPathInput = { |
| 77 | + path, |
| 78 | + options: { |
| 79 | + subpathStrategy, |
| 80 | + useAccelerateEndpoint, |
| 81 | + pageSize, |
| 82 | + nextToken, |
| 83 | + }, |
| 84 | + }; |
| 85 | + |
| 86 | + const listAllWithPathInput: ListAllWithPathInput = { |
| 87 | + path, |
| 88 | + options: { |
| 89 | + listAll: true, |
| 90 | + subpathStrategy, |
| 91 | + useAccelerateEndpoint, |
| 92 | + // @ts-expect-error pageSize is not part of this input |
| 93 | + pageSize, |
| 94 | + }, |
| 95 | + }; |
| 96 | + |
| 97 | + type Tests = [ |
| 98 | + Expect<Equal<typeof listPaginateInput, ListPaginateInput>>, |
| 99 | + Expect<Equal<typeof listAllInput, ListAllInput>>, |
| 100 | + Expect< |
| 101 | + Equal<typeof listPaginateWithPathInput, ListPaginateWithPathInput> |
| 102 | + >, |
| 103 | + Expect<Equal<typeof listAllWithPathInput, ListAllWithPathInput>>, |
| 104 | + ]; |
| 105 | + type Result = Expect<Equal<Tests, [true, true, true, true]>>; |
| 106 | + } |
| 107 | + }); |
| 108 | +}); |
| 109 | + |
| 110 | +describe('List API ouput types', () => { |
| 111 | + test('should compile', () => { |
| 112 | + function handleTest({ |
| 113 | + listOutputItems, |
| 114 | + nextToken, |
| 115 | + excludedSubpaths, |
| 116 | + listOutputItemsWithPath, |
| 117 | + }: Output) { |
| 118 | + const listPaginateOutput: ListPaginateOutput = { |
| 119 | + items: listOutputItems, |
| 120 | + nextToken, |
| 121 | + // @ts-expect-error excludeSubpaths is not part of this output |
| 122 | + excludedSubpaths, |
| 123 | + }; |
| 124 | + |
| 125 | + const listAllOutput: ListAllOutput = { |
| 126 | + items: listOutputItems, |
| 127 | + // @ts-expect-error excludeSubpaths is not part of this output |
| 128 | + excludedSubpaths, |
| 129 | + }; |
| 130 | + |
| 131 | + const listPaginateWithPathOutput: ListPaginateWithPathOutput = { |
| 132 | + items: listOutputItemsWithPath, |
| 133 | + nextToken, |
| 134 | + excludedSubpaths, |
| 135 | + }; |
| 136 | + |
| 137 | + const listAllWithPathOutput: ListAllWithPathOutput = { |
| 138 | + items: listOutputItemsWithPath, |
| 139 | + excludedSubpaths, |
| 140 | + }; |
| 141 | + |
| 142 | + type Tests = [ |
| 143 | + Expect<Equal<typeof listPaginateOutput, ListPaginateOutput>>, |
| 144 | + Expect<Equal<typeof listAllOutput, ListAllOutput>>, |
| 145 | + Expect< |
| 146 | + Equal<typeof listPaginateWithPathOutput, ListPaginateWithPathOutput> |
| 147 | + >, |
| 148 | + Expect<Equal<typeof listAllWithPathOutput, ListAllWithPathOutput>>, |
| 149 | + ]; |
| 150 | + |
| 151 | + type Result = Expect<Equal<Tests, [true, true, true, true]>>; |
| 152 | + } |
| 153 | + }); |
| 154 | +}); |
0 commit comments