@sprucelabs/spruce-cli 23.1.0 → 24.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/LICENSE +21 -0
  3. package/build/__tests__/behavioral/DeployingToSandbox.test.d.ts +6 -1
  4. package/build/__tests__/behavioral/DeployingToSandbox.test.js +54 -35
  5. package/build/__tests__/behavioral/DeployingToSandbox.test.js.map +1 -1
  6. package/build/__tests__/behavioral/conversations/CreatingAConversationTopic.test.js +2 -2
  7. package/build/__tests__/behavioral/conversations/CreatingAConversationTopic.test.js.map +1 -1
  8. package/build/__tests__/behavioral/conversations/RegisteringConversationsOnBoot.test.js +1 -1
  9. package/build/__tests__/behavioral/conversations/RegisteringConversationsOnBoot.test.js.map +1 -1
  10. package/build/__tests__/behavioral/conversations/TestingAConversation.test.js +5 -5
  11. package/build/__tests__/behavioral/conversations/TestingAConversation.test.js.map +1 -1
  12. package/build/__tests__/behavioral/organization/CreatingAnOrg.test.js.map +1 -1
  13. package/build/__tests__/behavioral/schemas/CreatingSchemasWithGenerics.test.js +1 -1
  14. package/build/__tests__/behavioral/schemas/CreatingSchemasWithGenerics.test.js.map +1 -1
  15. package/build/__tests__/behavioral/tests/migrationToInstance/AbstractInstanceTest.d.ts +11 -0
  16. package/build/__tests__/behavioral/tests/migrationToInstance/AbstractInstanceTest.js +49 -0
  17. package/build/__tests__/behavioral/tests/migrationToInstance/AbstractInstanceTest.js.map +1 -0
  18. package/build/__tests__/behavioral/tests/migrationToInstance/InstanceBasedTesting.test.d.ts +5 -0
  19. package/build/__tests__/behavioral/tests/migrationToInstance/InstanceBasedTesting.test.js +34 -0
  20. package/build/__tests__/behavioral/tests/migrationToInstance/InstanceBasedTesting.test.js.map +1 -0
  21. package/build/__tests__/behavioral/tests/migrationToInstance/MigratingTests.test.d.ts +12 -0
  22. package/build/__tests__/behavioral/tests/migrationToInstance/MigratingTests.test.js +88 -0
  23. package/build/__tests__/behavioral/tests/migrationToInstance/MigratingTests.test.js.map +1 -0
  24. package/build/__tests__/behavioral/tests/migrationToInstance/StaticTestFinder.test.d.ts +13 -0
  25. package/build/__tests__/behavioral/tests/migrationToInstance/StaticTestFinder.test.js +109 -0
  26. package/build/__tests__/behavioral/tests/migrationToInstance/StaticTestFinder.test.js.map +1 -0
  27. package/build/__tests__/behavioral/tests/migrationToInstance/StaticTestsWhenAlreadyExists.test.d.ts +4 -0
  28. package/build/__tests__/behavioral/tests/migrationToInstance/StaticTestsWhenAlreadyExists.test.js +29 -0
  29. package/build/__tests__/behavioral/tests/migrationToInstance/StaticTestsWhenAlreadyExists.test.js.map +1 -0
  30. package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceMigrator.test.d.ts +26 -0
  31. package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceMigrator.test.js +259 -0
  32. package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceMigrator.test.js.map +1 -0
  33. package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceTestFileMigrator.test.d.ts +26 -0
  34. package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceTestFileMigrator.test.js +202 -0
  35. package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceTestFileMigrator.test.js.map +1 -0
  36. package/build/__tests__/behavioral/tests/migrationToInstance/support/AbstractInstanceTest.txt +24 -0
  37. package/build/__tests__/behavioral/tests/migrationToInstance/support/AbstractStaticTest.txt +24 -0
  38. package/build/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest.txt +36 -0
  39. package/build/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest2.txt +63 -0
  40. package/build/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest3.txt +222 -0
  41. package/build/__tests__/behavioral/tests/migrationToInstance/support/StaticTest.txt +34 -0
  42. package/build/__tests__/behavioral/tests/migrationToInstance/support/StaticTest2.txt +62 -0
  43. package/build/__tests__/behavioral/tests/migrationToInstance/support/StaticTest3.txt +221 -0
  44. package/build/__tests__/behavioral/tests/migrationToInstance/testFileContentsGenerators.d.ts +2 -0
  45. package/build/__tests__/behavioral/tests/migrationToInstance/testFileContentsGenerators.js +51 -0
  46. package/build/__tests__/behavioral/tests/migrationToInstance/testFileContentsGenerators.js.map +1 -0
  47. package/build/__tests__/behavioral/versions/ResolvingVersions.test.js +0 -3
  48. package/build/__tests__/behavioral/versions/ResolvingVersions.test.js.map +1 -1
  49. package/build/__tests__/implementation/OrganizationStore.test.js +2 -2
  50. package/build/__tests__/implementation/OrganizationStore.test.js.map +1 -1
  51. package/build/__tests__/implementation/TerminalInterface.test.d.ts +1 -0
  52. package/build/__tests__/implementation/TerminalInterface.test.js +6 -0
  53. package/build/__tests__/implementation/TerminalInterface.test.js.map +1 -1
  54. package/build/__tests__/testDirsAndFiles/static_test_migration_1/src/__tests__/AnotherStaticTest.test.ts +33 -0
  55. package/build/__tests__/testDirsAndFiles/static_test_migration_1/src/__tests__/ShouldBeIgnored.ts +0 -0
  56. package/build/__tests__/testDirsAndFiles/static_test_migration_1/src/__tests__/StaticTest1.test.ts +33 -0
  57. package/build/__tests__/testDirsAndFiles/static_test_migration_2/src/DoNotInclude.ts +0 -0
  58. package/build/__tests__/testDirsAndFiles/static_test_migration_2/src/__tests__/AStaticTest.test.ts +33 -0
  59. package/build/__tests__/testDirsAndFiles/static_test_migration_2/src/__tests__/AnotherStaticTest1.test.ts +33 -0
  60. package/build/__tests__/testDirsAndFiles/static_test_migration_3/NotAFileThatShouldBeMigrated.ts +0 -0
  61. package/build/__tests__/testDirsAndFiles/static_test_migration_3/src/__tests__/AStaticTest2.test.ts +17 -0
  62. package/build/__tests__/testDirsAndFiles/static_test_migration_3/src/__tests__/AbstractWhateverTest.ts +3 -0
  63. package/build/errors/SpruceError.js +1 -1
  64. package/build/errors/SpruceError.js.map +1 -1
  65. package/build/features/skill/actions/LoginAction.js +1 -2
  66. package/build/features/skill/actions/LoginAction.js.map +1 -1
  67. package/build/features/test/actions/CreateAction.d.ts +1 -0
  68. package/build/features/test/actions/CreateAction.js +13 -0
  69. package/build/features/test/actions/CreateAction.js.map +1 -1
  70. package/build/features/test/actions/MigrateAction.d.ts +17 -0
  71. package/build/features/test/actions/MigrateAction.js +39 -0
  72. package/build/features/test/actions/MigrateAction.js.map +1 -0
  73. package/build/index.js +0 -0
  74. package/build/tests/staticToInstanceMigration/StaticTestFinder.d.ts +8 -0
  75. package/build/tests/staticToInstanceMigration/StaticTestFinder.js +23 -0
  76. package/build/tests/staticToInstanceMigration/StaticTestFinder.js.map +1 -0
  77. package/build/tests/staticToInstanceMigration/StaticToInstanceMigrator.d.ts +58 -0
  78. package/build/tests/staticToInstanceMigration/StaticToInstanceMigrator.js +48 -0
  79. package/build/tests/staticToInstanceMigration/StaticToInstanceMigrator.js.map +1 -0
  80. package/build/tests/staticToInstanceMigration/StaticToInstanceTestFileMigrator.d.ts +12 -0
  81. package/build/tests/staticToInstanceMigration/StaticToInstanceTestFileMigrator.js +138 -0
  82. package/build/tests/staticToInstanceMigration/StaticToInstanceTestFileMigrator.js.map +1 -0
  83. package/build/utilities/isCi.js +1 -1
  84. package/build/utilities/isCi.js.map +1 -1
  85. package/package.json +28 -45
  86. package/src/__tests__/behavioral/DeployingToSandbox.test.ts +77 -44
  87. package/src/__tests__/behavioral/conversations/CreatingAConversationTopic.test.ts +2 -2
  88. package/src/__tests__/behavioral/conversations/RegisteringConversationsOnBoot.test.ts +1 -1
  89. package/src/__tests__/behavioral/conversations/TestingAConversation.test.ts +5 -5
  90. package/src/__tests__/behavioral/organization/CreatingAnOrg.test.ts +0 -1
  91. package/src/__tests__/behavioral/schemas/CreatingSchemasWithGenerics.test.ts +2 -1
  92. package/src/__tests__/behavioral/tests/migrationToInstance/AbstractInstanceTest.ts +77 -0
  93. package/src/__tests__/behavioral/tests/migrationToInstance/InstanceBasedTesting.test.ts +19 -0
  94. package/src/__tests__/behavioral/tests/migrationToInstance/MigratingTests.test.ts +99 -0
  95. package/src/__tests__/behavioral/tests/migrationToInstance/StaticTestFinder.test.ts +72 -0
  96. package/src/__tests__/behavioral/tests/migrationToInstance/StaticTestsWhenAlreadyExists.test.ts +31 -0
  97. package/src/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceMigrator.test.ts +252 -0
  98. package/src/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceTestFileMigrator.test.ts +193 -0
  99. package/src/__tests__/behavioral/tests/migrationToInstance/support/AbstractInstanceTest.txt +24 -0
  100. package/src/__tests__/behavioral/tests/migrationToInstance/support/AbstractStaticTest.txt +24 -0
  101. package/src/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest.txt +36 -0
  102. package/src/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest2.txt +63 -0
  103. package/src/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest3.txt +222 -0
  104. package/src/__tests__/behavioral/tests/migrationToInstance/support/StaticTest.txt +34 -0
  105. package/src/__tests__/behavioral/tests/migrationToInstance/support/StaticTest2.txt +62 -0
  106. package/src/__tests__/behavioral/tests/migrationToInstance/support/StaticTest3.txt +221 -0
  107. package/src/__tests__/behavioral/tests/migrationToInstance/testFileContentsGenerators.ts +50 -0
  108. package/src/__tests__/behavioral/versions/ResolvingVersions.test.ts +1 -3
  109. package/src/__tests__/implementation/OrganizationStore.test.ts +6 -2
  110. package/src/__tests__/implementation/TerminalInterface.test.ts +9 -0
  111. package/src/__tests__/testDirsAndFiles/static_test_migration_1/src/__tests__/AnotherStaticTest.test.ts +33 -0
  112. package/src/__tests__/testDirsAndFiles/static_test_migration_1/src/__tests__/ShouldBeIgnored.ts +0 -0
  113. package/src/__tests__/testDirsAndFiles/static_test_migration_1/src/__tests__/StaticTest1.test.ts +33 -0
  114. package/src/__tests__/testDirsAndFiles/static_test_migration_2/src/DoNotInclude.ts +0 -0
  115. package/src/__tests__/testDirsAndFiles/static_test_migration_2/src/__tests__/AStaticTest.test.ts +33 -0
  116. package/src/__tests__/testDirsAndFiles/static_test_migration_2/src/__tests__/AnotherStaticTest1.test.ts +33 -0
  117. package/src/__tests__/testDirsAndFiles/static_test_migration_3/NotAFileThatShouldBeMigrated.ts +0 -0
  118. package/src/__tests__/testDirsAndFiles/static_test_migration_3/src/__tests__/AStaticTest2.test.ts +17 -0
  119. package/src/__tests__/testDirsAndFiles/static_test_migration_3/src/__tests__/AbstractWhateverTest.ts +3 -0
  120. package/src/errors/SpruceError.ts +1 -1
  121. package/src/features/skill/actions/LoginAction.ts +8 -7
  122. package/src/features/test/actions/CreateAction.ts +17 -0
  123. package/src/features/test/actions/MigrateAction.ts +41 -0
  124. package/src/tests/staticToInstanceMigration/StaticTestFinder.ts +25 -0
  125. package/src/tests/staticToInstanceMigration/StaticToInstanceMigrator.ts +73 -0
  126. package/src/tests/staticToInstanceMigration/StaticToInstanceTestFileMigrator.ts +197 -0
  127. package/src/utilities/isCi.ts +1 -1
  128. package/.DS_Store +0 -0
  129. package/.env +0 -25
  130. package/.env-dev +0 -24
  131. package/.eslintcache +0 -1
  132. package/dist/spruce-darwin-arm64 +0 -0
  133. package/dist/spruce-linux-arm64 +0 -0
  134. package/junit.xml +0 -42
  135. package/yarn-error.log +0 -597
@@ -0,0 +1,252 @@
1
+ import AbstractSpruceTest, {
2
+ test,
3
+ assert,
4
+ errorAssert,
5
+ suite,
6
+ generateId,
7
+ } from '@sprucelabs/test-utils'
8
+ import StaticTestFinderImpl, {
9
+ StaticTestFinder,
10
+ } from '../../../../tests/staticToInstanceMigration/StaticTestFinder'
11
+ import StaticToInstanceMigratorImpl, {
12
+ StaticToInstanceMigrator,
13
+ } from '../../../../tests/staticToInstanceMigration/StaticToInstanceMigrator'
14
+ import StaticToInstanceTestFileMigratorImpl, {
15
+ StaticToInstanceTestFileMigrator,
16
+ } from '../../../../tests/staticToInstanceMigration/StaticToInstanceTestFileMigrator'
17
+
18
+ @suite()
19
+ export default class StaticToInstanceMigratorTest extends AbstractSpruceTest {
20
+ private testFinder: FakeStaticTestFinder
21
+ private testFileMigrator: FakeFileMigrator
22
+ private migrator: StaticToInstanceMigrator
23
+ private readFiles: string[] = []
24
+ private fakedFileContents: Record<string, string> = {}
25
+ private lastWrittenFile?: { destination: string; contents: string }
26
+
27
+ public constructor() {
28
+ super()
29
+
30
+ StaticTestFinderImpl.Class = FakeStaticTestFinder
31
+ StaticToInstanceTestFileMigratorImpl.Class = FakeFileMigrator
32
+
33
+ StaticToInstanceMigratorImpl.diskUtil.readFile = (source) => {
34
+ this.readFiles.push(source)
35
+ return this.fakedFileContents[source] ?? generateId()
36
+ }
37
+
38
+ StaticToInstanceMigratorImpl.diskUtil.writeFile = (
39
+ destination: string,
40
+ contents: string
41
+ ) => {
42
+ this.lastWrittenFile = {
43
+ destination,
44
+ contents,
45
+ }
46
+ }
47
+
48
+ this.testFinder = StaticTestFinderImpl.Finder() as FakeStaticTestFinder
49
+ this.testFileMigrator =
50
+ StaticToInstanceTestFileMigratorImpl.Migrator() as FakeFileMigrator
51
+
52
+ this.migrator = StaticToInstanceMigratorImpl.Migrator({
53
+ testFinder: this.testFinder,
54
+ testFileMigrator: this.testFileMigrator,
55
+ })
56
+ }
57
+
58
+ @test()
59
+ protected throwsWithMissing() {
60
+ const err = assert.doesThrow(() =>
61
+ //@ts-ignore
62
+ StaticToInstanceMigratorImpl.Migrator()
63
+ )
64
+ errorAssert.assertError(err, 'MISSING_PARAMETERS', {
65
+ parameters: ['testFinder', 'testFileMigrator'],
66
+ })
67
+ }
68
+
69
+ @test()
70
+ protected async runThrowsWithMissing() {
71
+ //@ts-ignore
72
+ const err = await assert.doesThrowAsync(() => this.migrator.run())
73
+ errorAssert.assertError(err, 'MISSING_PARAMETERS', {
74
+ parameters: ['lookupDir'],
75
+ })
76
+ }
77
+
78
+ @test()
79
+ protected async passesLookupDirToTestFinder() {
80
+ const path = generateId()
81
+ await this.run(path)
82
+ assert.isEqual(this.testFinder.lastLookupDir, path)
83
+ }
84
+
85
+ @test('returns stats based on 3 tests found', ['a', 'b', 'c'])
86
+ @test('returns stats based on 0 tests found', [])
87
+ protected async returnsStatsBasedOnTestsFound(results: string[]) {
88
+ this.setFakedFinderResults(results)
89
+ const stats = await this.run()
90
+ assert.isEqualDeep(stats, {
91
+ totalTestsUpdated: this.testFinder.fakedResults.length,
92
+ totalTestsSkipped: 0,
93
+ })
94
+ }
95
+
96
+ @test('passes one files contents to migrator', 'a')
97
+ @test('passes another files contents to migrator', 'b')
98
+ protected async passesOneFilesContentsToMigrator(filename: string) {
99
+ this.setFakedFinderResults([filename])
100
+ await this.run()
101
+ assert.isEqualDeep(this.readFiles, [filename])
102
+ }
103
+
104
+ @test()
105
+ protected async passesResultsOfFileToMigrator() {
106
+ this.setFakedFinderResults(['a'])
107
+ this.setFakedFileContents({
108
+ a: generateId(),
109
+ })
110
+ await this.run()
111
+
112
+ this.assertContentsPassedToFileMigratorEquals([
113
+ this.fakedFileContents['a'],
114
+ ])
115
+ }
116
+
117
+ @test()
118
+ protected async passesResultsOfMultipleFilesToMigrator() {
119
+ const contents1 = generateId()
120
+ const contents2 = generateId()
121
+
122
+ this.setFakedFinderResults(['what', 'the'])
123
+
124
+ this.setFakedFileContents({
125
+ what: contents1,
126
+ the: contents2,
127
+ })
128
+
129
+ await this.run()
130
+
131
+ this.assertContentsPassedToFileMigratorEquals([contents1, contents2])
132
+ }
133
+
134
+ @test()
135
+ protected async writesResponseOfMigrate() {
136
+ const filename = generateId()
137
+
138
+ this.setFakedFinderResults([filename])
139
+ this.setFakedFileContents({
140
+ [filename]: generateId(),
141
+ })
142
+
143
+ await this.run()
144
+
145
+ assert.isEqualDeep(this.lastWrittenFile, {
146
+ destination: filename,
147
+ contents: this.testFileMigrator.fakedMigrateResponse,
148
+ })
149
+ }
150
+
151
+ @test()
152
+ protected async returnsSkippedIfMigratedIsTheSame() {
153
+ this.setFakedFinderResults(['a'])
154
+ const contents = generateId()
155
+ this.setFakedFileContents({
156
+ a: contents,
157
+ })
158
+
159
+ this.setMigrateFileResponse(contents)
160
+
161
+ const stats = await this.run()
162
+ assert.isEqualDeep(stats, {
163
+ totalTestsUpdated: 0,
164
+ totalTestsSkipped: 1,
165
+ })
166
+ }
167
+
168
+ @test()
169
+ protected async countsSkippedAndMatched() {
170
+ const contents1 = generateId()
171
+ const contents2 = generateId()
172
+
173
+ this.setFakedFinderResults(['what', 'the', 'heck'])
174
+ this.setFakedFileContents({
175
+ what: contents1,
176
+ the: contents2,
177
+ heck: generateId(),
178
+ })
179
+
180
+ this.testFileMigrator.fakedMigrateResponsesByContents = {
181
+ [contents1]: contents1,
182
+ [contents2]: contents2,
183
+ }
184
+
185
+ const stats = await this.run()
186
+ assert.isEqualDeep(stats, {
187
+ totalTestsUpdated: 1,
188
+ totalTestsSkipped: 2,
189
+ })
190
+ }
191
+
192
+ @test()
193
+ protected async doesNotWriteFileThatDidNotChange() {
194
+ this.setFakedFinderResults(['a'])
195
+ const contents = generateId()
196
+ this.setFakedFileContents({
197
+ a: contents,
198
+ })
199
+
200
+ this.setMigrateFileResponse(contents)
201
+
202
+ await this.run()
203
+ assert.isUndefined(this.lastWrittenFile)
204
+ }
205
+
206
+ private setMigrateFileResponse(contents: string) {
207
+ this.testFileMigrator.fakedMigrateResponse = contents
208
+ }
209
+
210
+ private assertContentsPassedToFileMigratorEquals(expected: string[]) {
211
+ assert.isEqualDeep(
212
+ this.testFileMigrator.contentsPassedToMigrate,
213
+ expected
214
+ )
215
+ }
216
+
217
+ private setFakedFileContents(contents: Record<string, string>) {
218
+ this.fakedFileContents = contents
219
+ }
220
+
221
+ private setFakedFinderResults(results: string[]) {
222
+ this.testFinder.fakedResults = results
223
+ }
224
+
225
+ private async run(path?: string) {
226
+ return await this.migrator.run(path ?? generateId())
227
+ }
228
+ }
229
+
230
+ class FakeStaticTestFinder implements StaticTestFinder {
231
+ public lastLookupDir?: string
232
+ public fakedResults: string[] = []
233
+
234
+ public async find(lookupDir: string): Promise<string[]> {
235
+ this.lastLookupDir = lookupDir
236
+ return this.fakedResults
237
+ }
238
+ }
239
+
240
+ class FakeFileMigrator implements StaticToInstanceTestFileMigrator {
241
+ public contentsPassedToMigrate: string[] = []
242
+ public fakedMigrateResponse = generateId()
243
+ public fakedMigrateResponsesByContents: Record<string, string> = {}
244
+
245
+ public migrate(contents: string): string {
246
+ this.contentsPassedToMigrate.push(contents)
247
+ return (
248
+ this.fakedMigrateResponsesByContents[contents] ??
249
+ this.fakedMigrateResponse
250
+ )
251
+ }
252
+ }
@@ -0,0 +1,193 @@
1
+ import { diskUtil } from '@sprucelabs/spruce-skill-utils'
2
+ import AbstractSpruceTest, {
3
+ test,
4
+ assert,
5
+ errorAssert,
6
+ suite,
7
+ } from '@sprucelabs/test-utils'
8
+ import StaticToInstanceTestFileMigratorImpl, {
9
+ StaticToInstanceTestFileMigrator,
10
+ } from '../../../../tests/staticToInstanceMigration/StaticToInstanceTestFileMigrator'
11
+
12
+ @suite()
13
+ export default class StaticToInstanceTestFileMigratorTest extends AbstractSpruceTest {
14
+ private migrator: StaticToInstanceTestFileMigrator =
15
+ StaticToInstanceTestFileMigratorImpl.Migrator()
16
+
17
+ @test()
18
+ protected throwsWithMissing() {
19
+ //@ts-ignore
20
+ const err = assert.doesThrow(() => this.migrate())
21
+ errorAssert.assertError(err, 'MISSING_PARAMETERS', {
22
+ parameters: ['contents'],
23
+ })
24
+ }
25
+
26
+ @test()
27
+ protected returnsEmptyString() {
28
+ this.assertMigratedEquals('', '')
29
+ }
30
+
31
+ @test()
32
+ protected fixesStaticFunction() {
33
+ this.assertMigratedEquals(
34
+ `@test()
35
+ protected static myTest() {}`,
36
+ `@test()
37
+ protected myTest() {}`
38
+ )
39
+ }
40
+
41
+ @test()
42
+ protected fixesStaticAsyncFunctions() {
43
+ this.assertMigratedEquals(
44
+ `@test()
45
+ protected static async myTest() {}`,
46
+ `@test()
47
+ protected async myTest() {}`
48
+ )
49
+ }
50
+
51
+ @test()
52
+ protected doesNotMessWithStaticInVariableName() {
53
+ this.assertMigratedEquals(
54
+ `protected staticInName() {}`,
55
+ `protected staticInName() {}`
56
+ )
57
+ }
58
+
59
+ @test()
60
+ protected addsSuiteDecoratorToClassIfNotThere() {
61
+ this.assertMigratedEquals(
62
+ `export default class Test {}`,
63
+ `@suite()\nexport default class Test {}`
64
+ )
65
+ }
66
+
67
+ @test()
68
+ protected doesNotAddSuitIfAnotherClassExported() {
69
+ this.assertMigratedEquals(
70
+ `export class Test {}`,
71
+ `export class Test {}`
72
+ )
73
+ }
74
+
75
+ @test()
76
+ protected doesNotAddSuiteIfAlreadyThere() {
77
+ this.assertMigratedEquals(
78
+ `@suite()\nexport default class Test {}`,
79
+ `@suite()\nexport default class Test {}`
80
+ )
81
+ }
82
+
83
+ @test()
84
+ protected addsImportIfNotThere() {
85
+ this.assertMigratedEquals(
86
+ `import { test } from '@sprucelabs/test-utils'`,
87
+ `import { test, suite } from '@sprucelabs/test-utils'`
88
+ )
89
+ }
90
+
91
+ @test()
92
+ protected doesNotMessWithAnythingWithTestInName() {
93
+ this.assertMigratedEquals(
94
+ `protected testing() {}`,
95
+ `protected testing() {}`
96
+ )
97
+ }
98
+
99
+ @test()
100
+ protected doesNoIncludeSuiteTwice() {
101
+ this.assertMigratedEquals(
102
+ `import { test, suite } from '@sprucelabs/test-utils'`,
103
+ `import { test, suite } from '@sprucelabs/test-utils'`
104
+ )
105
+ }
106
+
107
+ @test()
108
+ protected includesSuiteEvenIfSuiteIsInAMethodName() {
109
+ this.assertMigratedEquals(
110
+ `import { test } from '@sprucelabs/test-utils
111
+ protected suiteMethod() {}`,
112
+ `import { test, suite } from '@sprucelabs/test-utils
113
+ protected suiteMethod() {}`
114
+ )
115
+ }
116
+
117
+ @test()
118
+ protected includesSuiteWithMultipleImports() {
119
+ this.assertMigratedEquals(
120
+ `import AbstractSpruceTest, {
121
+ test,
122
+ assert,
123
+ errorAssert,
124
+ } from '@sprucelabs/test-utils'`,
125
+ `import AbstractSpruceTest, {
126
+ test,
127
+ suite,
128
+ assert,
129
+ errorAssert,
130
+ } from '@sprucelabs/test-utils'`
131
+ )
132
+ }
133
+
134
+ @test()
135
+ protected canMigrateWholeTest() {
136
+ const before = this.readTestFile('StaticTest.txt')
137
+ const expected = this.readTestFile('InstanceTest.txt')
138
+
139
+ this.assertMigratedEquals(before, expected)
140
+ }
141
+
142
+ @test()
143
+ protected properlyMigrationsAbstractTests() {
144
+ const before = this.readTestFile('AbstractStaticTest.txt')
145
+ const expected = this.readTestFile('AbstractInstanceTest.txt')
146
+
147
+ this.assertMigratedEquals(before, expected)
148
+ }
149
+
150
+ @test()
151
+ protected canMigrateMoreComplexTest() {
152
+ const before = this.readTestFile('StaticTest2.txt')
153
+ const expected = this.readTestFile('InstanceTest2.txt')
154
+
155
+ this.assertMigratedEquals(before, expected)
156
+ }
157
+
158
+ @test()
159
+ protected canMigrateAnotherComplexTest() {
160
+ const before = this.readTestFile('StaticTest3.txt')
161
+ const expected = this.readTestFile('InstanceTest3.txt')
162
+
163
+ this.assertMigratedEquals(before, expected)
164
+ }
165
+
166
+ private readTestFile(name: string) {
167
+ return diskUtil.readFile(this.resolveTestClassPath(name))
168
+ }
169
+
170
+ private resolveTestClassPath(name: string) {
171
+ return this.resolvePath(__dirname, 'support', name)
172
+ }
173
+
174
+ private assertMigratedEquals(contents: string, expected: string) {
175
+ const actual = this.migrate(contents)
176
+
177
+ const cleanedActual = this.cleanString(actual)
178
+ const cleanedExpected = this.cleanString(expected)
179
+
180
+ assert.isTrue(
181
+ cleanedActual == cleanedExpected,
182
+ `${actual}\n\ndoes not equal\n\n${expected}`
183
+ )
184
+ }
185
+
186
+ private cleanString(contents: string) {
187
+ return contents.replace(/\s{2,}/g, ' ').trim()
188
+ }
189
+
190
+ private migrate(contents: string) {
191
+ return this.migrator.migrate(contents)
192
+ }
193
+ }
@@ -0,0 +1,24 @@
1
+ import { AbstractSpruceFixtureTest } from '@sprucelabs/spruce-test-fixtures'
2
+ import { assert } from '@sprucelabs/test-utils'
3
+ import HomeIntegrationsStore from '../../stores/HomeIntegrations.store'
4
+ import EventFaker from './EventFaker'
5
+
6
+ export default abstract class AbstractGoogleTest extends AbstractSpruceFixtureTest {
7
+ protected eventFaker!: EventFaker
8
+ private homeIntegrations!: HomeIntegrationsStore
9
+
10
+ protected async beforeEach(): Promise<void> {
11
+ await super.beforeEach()
12
+ this.eventFaker = new EventFaker()
13
+ this.homeIntegrations = await this.stores.getStore('homeIntegrations')
14
+ }
15
+
16
+ protected async getFirstHomeIntegration() {
17
+ const match = await this.homeIntegrations.findOne(
18
+ {},
19
+ { shouldIncludePrivateFields: true }
20
+ )
21
+ assert.isTruthy(match, 'No home integration found')
22
+ return match
23
+ }
24
+ }
@@ -0,0 +1,24 @@
1
+ import { AbstractSpruceFixtureTest } from '@sprucelabs/spruce-test-fixtures'
2
+ import { assert } from '@sprucelabs/test-utils'
3
+ import HomeIntegrationsStore from '../../stores/HomeIntegrations.store'
4
+ import EventFaker from './EventFaker'
5
+
6
+ export default abstract class AbstractGoogleTest extends AbstractSpruceFixtureTest {
7
+ protected static eventFaker: EventFaker
8
+ private static homeIntegrations: HomeIntegrationsStore
9
+
10
+ protected static async beforeEach(): Promise<void> {
11
+ await super.beforeEach()
12
+ this.eventFaker = new EventFaker()
13
+ this.homeIntegrations = await this.stores.getStore('homeIntegrations')
14
+ }
15
+
16
+ protected static async getFirstHomeIntegration() {
17
+ const match = await this.homeIntegrations.findOne(
18
+ {},
19
+ { shouldIncludePrivateFields: true }
20
+ )
21
+ assert.isTruthy(match, 'No home integration found')
22
+ return match
23
+ }
24
+ }
@@ -0,0 +1,36 @@
1
+ import { assertOptions } from '@sprucelabs/schema'
2
+ import { fake } from '@sprucelabs/spruce-test-fixtures'
3
+ import AbstractSpruceTest, {
4
+ test,
5
+ suite,
6
+ assert,
7
+ errorAssert,
8
+ } from '@sprucelabs/test-utils'
9
+
10
+ @fake.login()
11
+ @suite()
12
+ export default class StaticTestFinderTest extends AbstractSpruceTest {
13
+ @test()
14
+ protected async throwsWithMissing() {
15
+ const finder = StaticTestFinder.Finder()
16
+ const err = await assert.doesThrowAsync(() => finder.find())
17
+ errorAssert.assertError(err, 'MISSING_PARAMETERS', {
18
+ parameters: ['lookupDir'],
19
+ })
20
+ }
21
+
22
+ @test()
23
+ protected async yourNextTest() {
24
+ assert.isTrue(false)
25
+ }
26
+ }
27
+
28
+ class StaticTestFinder {
29
+ public static Finder() {
30
+ return new this()
31
+ }
32
+
33
+ public async find() {
34
+ assertOptions({}, ['lookupDir'])
35
+ }
36
+ }
@@ -0,0 +1,63 @@
1
+ import { fake, seed } from '@sprucelabs/spruce-test-fixtures'
2
+ import { assert, test, suite } from '@sprucelabs/test-utils'
3
+ import { HomeIntegration, PublicHomeIntegration } from '../../../google.types'
4
+ import AbstractGoogleTest from '../../support/AbstractGoogleTest'
5
+
6
+ @fake.login()
7
+ @suite()
8
+ export default class ListHomeIntegrationsLIstenerTest extends AbstractGoogleTest {
9
+ protected async beforeEach(): Promise<void> {
10
+ await super.beforeEach()
11
+ await this.bootSkill()
12
+ }
13
+
14
+ protected async afterEach(): Promise<void> {
15
+ }
16
+
17
+ @test()
18
+ protected async skillIsListening() {
19
+ await this.emit()
20
+ }
21
+
22
+ @test()
23
+ @seed('homeIntegrations', 1)
24
+ protected async canReturnFirstHomeIntegration() {
25
+ const expected = await this.getFirstHomeIntegration()
26
+ const integrations = await this.emit()
27
+ assert.isLength(integrations, 1)
28
+ const first = integrations[0]
29
+ this.assertIntegrationEqualsExpected(first, expected)
30
+ }
31
+
32
+ @test()
33
+ @seed('homeIntegrations', 2)
34
+ protected async canReturnMultipleHomeIntegrations() {
35
+ const expected = await this.homeIntegrations.find(
36
+ {},
37
+ {},
38
+ { shouldIncludePrivateFields: true }
39
+ )
40
+ const integrations = await this.emit()
41
+ assert.isLength(integrations, 2)
42
+ this.assertIntegrationEqualsExpected(integrations[0], expected[0])
43
+ this.assertIntegrationEqualsExpected(integrations[1], expected[1])
44
+ }
45
+
46
+ private assertIntegrationEqualsExpected(
47
+ first: PublicHomeIntegration,
48
+ expected: HomeIntegration
49
+ ) {
50
+ assert.isEqual(first.id, expected.id)
51
+ assert.isEqual(first.name, expected.name)
52
+ assert.isEqual(first.description, expected.description)
53
+ }
54
+
55
+ private async emit() {
56
+ const [{ integrations }] =
57
+ await this.fakedClient.emitAndFlattenResponses(
58
+ 'google.list-home-integrations::v2025_02_08'
59
+ )
60
+
61
+ return integrations
62
+ }
63
+ }