fix: Add postAuthenticate hook for source control preferences (no-changelog) (#6629)

* feat: handle source control settings in post-authenticate app hook

* fix: only trigger post authenticate when logging in

* chore: remove console.log

* chore: fix linting issues

* test: update source control test
This commit is contained in:
Alex Grozav
2023-07-10 12:35:36 +02:00
committed by GitHub
parent 9460bdd3be
commit a95862b6e2
4 changed files with 44 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
<script lang="ts" setup>
import { computed, reactive, onBeforeMount, ref } from 'vue';
import { computed, reactive, ref, onMounted } from 'vue';
import type { Rule, RuleGroup } from 'n8n-design-system/types';
import { MODAL_CONFIRM, VALID_EMAIL_REGEX } from '@/constants';
import { useUIStore, useSourceControlStore } from '@/stores';
@@ -101,11 +101,16 @@ const goToUpgrade = () => {
uiStore.goToUpgrade('source-control', 'upgrade-source-control');
};
onBeforeMount(() => {
const initialize = async () => {
await sourceControlStore.getPreferences();
if (sourceControlStore.preferences.connected) {
isConnected.value = true;
void sourceControlStore.getBranches();
}
};
onMounted(async () => {
await initialize();
});
const formValidationStatus = reactive<Record<string, boolean>>({

View File

@@ -69,10 +69,13 @@ describe('SettingsSourceControl', () => {
it('should render user flow happy path', async () => {
vi.spyOn(settingsStore, 'isEnterpriseFeatureEnabled').mockReturnValue(true);
const updatePreferencesSpy = vi.spyOn(sourceControlStore, 'updatePreferences');
const { container, getByTestId, queryByTestId, getByRole } = renderComponent();
await waitFor(() => expect(sourceControlStore.preferences.publicKey).not.toEqual(''));
const connectButton = getByTestId('source-control-connect-button');
expect(connectButton).toBeDisabled();
@@ -104,7 +107,7 @@ describe('SettingsSourceControl', () => {
await userEvent.type(authorEmail, 'com');
await userEvent.tab();
expect(connectButton).toBeEnabled();
await waitFor(() => expect(connectButton).toBeEnabled());
expect(queryByTestId('source-control-save-settings-button')).not.toBeInTheDocument();
await userEvent.click(connectButton);
@@ -139,5 +142,5 @@ describe('SettingsSourceControl', () => {
await waitFor(() =>
expect(queryByTestId('source-control-connected-content')).not.toBeInTheDocument(),
);
});
}, 10000);
});