(t *testing.T)
| 639 | } |
| 640 | |
| 641 | func TestConfig_SetDefaultAppIDForTenant(t *testing.T) { |
| 642 | t.Run("it successfully saves a new default app id for the tenant", func(t *testing.T) { |
| 643 | tempFile := createTempConfigFile(t, []byte(`{ |
| 644 | "install_id": "3998b053-dd7f-4bfe-bb10-c4f3a96a0180", |
| 645 | "default_tenant": "auth0-cli.eu.auth0.com", |
| 646 | "tenants": { |
| 647 | "auth0-cli.eu.auth0.com": { |
| 648 | "name": "auth0-cli", |
| 649 | "domain": "auth0-cli.eu.auth0.com", |
| 650 | "access_token": "eyfSaswe", |
| 651 | "expires_at": "2023-04-18T11:18:07.998809Z", |
| 652 | "client_id": "secret" |
| 653 | } |
| 654 | } |
| 655 | }`)) |
| 656 | |
| 657 | expectedConfig := `{ |
| 658 | "install_id": "3998b053-dd7f-4bfe-bb10-c4f3a96a0180", |
| 659 | "default_tenant": "auth0-cli.eu.auth0.com", |
| 660 | "tenants": { |
| 661 | "auth0-cli.eu.auth0.com": { |
| 662 | "name": "auth0-cli", |
| 663 | "domain": "auth0-cli.eu.auth0.com", |
| 664 | "access_token": "eyfSaswe", |
| 665 | "expires_at": "2023-04-18T11:18:07.998809Z", |
| 666 | "default_app_id": "appID123456", |
| 667 | "client_id": "secret" |
| 668 | } |
| 669 | } |
| 670 | }` |
| 671 | |
| 672 | config := &Config{path: tempFile} |
| 673 | err := config.SetDefaultAppIDForTenant("auth0-cli.eu.auth0.com", "appID123456") |
| 674 | assert.NoError(t, err) |
| 675 | assertConfigFileMatches(t, config.path, expectedConfig) |
| 676 | }) |
| 677 | |
| 678 | t.Run("it throws an error if there's an issue with the config file", func(t *testing.T) { |
| 679 | config := &Config{path: "i-dont-exist.json"} |
| 680 | |
| 681 | err := config.SetDefaultAppIDForTenant("tenant", "appID123456") |
| 682 | assert.EqualError(t, err, "config.json file is missing") |
| 683 | }) |
| 684 | } |
| 685 | |
| 686 | func TestConfig_IsLoggedInWithTenant(t *testing.T) { |
| 687 | t.Run("it returns true when there is a tenant in the config and its access token is valid", func(t *testing.T) { |
nothing calls this directly
no test coverage detected