Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat | generate token for secret #42

Closed
wants to merge 3 commits into from

Conversation

n370
Copy link
Contributor

@n370 n370 commented Mar 1, 2021

Closes: #5

This PR adds:

  • A back-end service wrapper mostly ported over from optic-web.
  • A bare bones <Secret /> component with a button to trigger the token generation.

components/Secret.js Outdated Show resolved Hide resolved
lib/secretsService.js Show resolved Hide resolved
@n370 n370 force-pushed the feat/generate-token-for-secret branch from 1f4e0f7 to 4984cb4 Compare March 2, 2021 21:46
@n370 n370 force-pushed the feat/generate-token-for-secret branch from 4984cb4 to 30f101a Compare March 2, 2021 21:54
@n370 n370 force-pushed the feat/generate-token-for-secret branch from 30f101a to f06fff2 Compare March 3, 2021 00:24
@n370
Copy link
Contributor Author

n370 commented Mar 3, 2021

@simoneb I guess I'm leaving this here for now. The code is functional and does the job of talking to the server to get a token. It works fine. There are a couple of things missing though.

it('should allow an authenticated user to scan a QR code', async () => {
const mockSecret = {
secret: 'mock-qr-secret',
account: 'test',
issuer: '',
uid: 'uid',
}
mockUseAuthRequest({
type: 'success',
params: {
id_token: 'token',
},
})
const addSecretsMock = jest.fn()
useSecrets.mockReturnValue({
isInitialized: true,
secrets: [],
add: addSecretsMock,
})
const getIdTokenMock = jest.fn().mockResolvedValue('id-token')
firebase.auth().onAuthStateChanged = jest.fn(callback =>
callback({
name: 'user',
uid: 'uid',
getIdToken: getIdTokenMock,
})
)
const { queryByText, getByA11yLabel } = renderWithTheme({
ui: <Main />,
})
await waitFor(() => expect(getIdTokenMock).toHaveBeenCalled())
expect(queryByText('Your Tokens')).not.toBeNull()
const showActionsButton = getByA11yLabel('show-actions')
fireEvent.press(showActionsButton)
const scanCodeButton = getByA11yLabel('Scan QR Code')
fireEvent.press(scanCodeButton)
await waitFor(() => expect(addSecretsMock).toHaveBeenCalledWith(mockSecret))
})

This unit test is for instance passing but not without logging an error to the console. I spent some time with it trying to figure out what was going on but at this point I think we should consider breaking it down into smaller tests. This one is already doing too much imho.

We're also missing writing new unit tests at least for the new class being added here.

salmanm added a commit that referenced this pull request May 5, 2021
* fix: remove unused imports

* feat: add back-end api wrapper

* feat: ask server for a token

* feat: improve home page ui

Co-authored-by: Dylson Valente Neto <[email protected]>
@salmanm
Copy link
Contributor

salmanm commented May 5, 2021

#80 included commits from this PR, so closing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

generate token for secret
3 participants