Skip to content

Commit

Permalink
record quickstart usage to telemetry, w/tests (#804)
Browse files Browse the repository at this point in the history
  • Loading branch information
purplecabbage authored Jun 25, 2024
1 parent 3787819 commit db0da64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/commands/app/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ class InitCommand extends TemplatesCommand {
}

async withQuickstart (fullRepo, githubPat) {
// telemetry hook for quickstart installs
await this.config.runHook('telemetry', { data: `installQuickstart:${fullRepo}` })

const octokit = new Octokit({
auth: githubPat ?? '',
userAgent: 'ADP App Builder v1'
Expand Down
7 changes: 6 additions & 1 deletion test/commands/app/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ beforeEach(() => {

command = new TheCommand([])
command.config = {
findCommand: jest.fn(() => ({}))
findCommand: jest.fn(() => ({})),
runHook: jest.fn()
}

command.selectTemplates = jest.fn()
Expand Down Expand Up @@ -313,6 +314,7 @@ describe('--no-login', () => {
command.argv = ['--no-login', '--standalone-app']
await command.run()

expect(command.config.runHook).not.toHaveBeenCalled()
expect(command.installTemplates).toHaveBeenCalledWith(installOptions)
expect(command.runCodeGenerators).toHaveBeenCalledWith(['base-app', 'add-ci', 'application'], false, 'cwd', 'basic')
expect(LibConsoleCLI.init).not.toHaveBeenCalled()
Expand All @@ -328,6 +330,7 @@ describe('--no-login', () => {
command.argv = ['--no-login', '--repo=adobe/appbuilder-quickstarts/qr-code']
await command.run()

expect(command.config.runHook).toHaveBeenCalled()
expect(command.installTemplates).not.toHaveBeenCalled()
expect(LibConsoleCLI.init).not.toHaveBeenCalled()
expect(importHelperLib.importConfigJson).not.toHaveBeenCalled()
Expand Down Expand Up @@ -356,6 +359,7 @@ describe('--no-login', () => {
command.argv = ['--login', '--repo=adobe/appbuilder-quickstarts/qr-code']
await command.run()

expect(command.config.runHook).toHaveBeenCalled()
expect(command.installTemplates).not.toHaveBeenCalled()
expect(LibConsoleCLI.init).toHaveBeenCalled()
expect(importHelperLib.importConfigJson).toHaveBeenCalled()
Expand All @@ -375,6 +379,7 @@ describe('--no-login', () => {

await command.run()

expect(command.config.runHook).toHaveBeenCalled()
expect(command.error).toHaveBeenCalledWith('--repo does not point to a valid Adobe App Builder app')
expect(command.installTemplates).not.toHaveBeenCalled()
expect(LibConsoleCLI.init).not.toHaveBeenCalled()
Expand Down

0 comments on commit db0da64

Please sign in to comment.