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: sky zoo #25

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/hooks/useSkyZoo.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { renderHook, waitFor } from '@testing-library/react';
import { describe, expect, test } from 'vitest';
import { useSkyZoo } from './useSkyZoo';
import { TestRouterProvider } from '@/test/helpers/test-router-provider';

describe('useSkyZoo', () => {
test('returns user position', async () => {
const { result } = renderHook(() => useSkyZoo({ did: 'did:plc:k6acu4chiwkixvdedcmdgmal' }), {
wrapper: ({ children }) => <TestRouterProvider>{children}</TestRouterProvider>,
});

expect(result.current.data).toBe(undefined);
expect(result.current.error).toBe(null);

await waitFor(() => expect(result.current.isSuccess).toBe(true));

Check failure on line 15 in src/hooks/useSkyZoo.test.tsx

View workflow job for this annotation

GitHub Actions / test (22.x)

src/hooks/useSkyZoo.test.tsx > useSkyZoo > returns user position

AssertionError: expected false to be true // Object.is equality Ignored nodes: comments, script, style <html> <head /> <body> <div /> </body> </html>... - Expected + Received - true + false ❯ src/hooks/useSkyZoo.test.tsx:15:58 ❯ runWithExpensiveErrorDiagnosticsDisabled node_modules/@testing-library/dom/dist/config.js:47:12 ❯ checkCallback node_modules/@testing-library/dom/dist/wait-for.js:124:77 ❯ Timeout.checkRealTimersCallback node_modules/@testing-library/dom/dist/wait-for.js:118:16

expect(result.current.data).toEqual({
did: 'did:plc:k6acu4chiwkixvdedcmdgmal',
pos_atproto: 13658725,
pos_bsky: 13591459,
createdAt: '2024-10-21T12:09:43.477Z',
});
});
});
17 changes: 17 additions & 0 deletions src/hooks/useSkyZoo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useQuery } from '@tanstack/react-query';

export function useSkyZoo({ did }: { did: string }) {
return useQuery({
queryKey: ['sky-zoo', { did }],
queryFn: async () => {
const response = await fetch(`https://skyzoo.blue/stats/plc/${did}`);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jycouet i get CORS errors when running this in tests. is there any chance the headers could be a little less restrictive?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are running test on what port ?

(I'm avoiding laptop until next Monday, but I'll do something)
Let me know ✌️

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a quick look, but don't manage to see the error test.
When I do npm run test, I don't get dirrectly failed test, I need to check the report. I'm missing something ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any reason you're restricting the CORS at all? why not just set it to *?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a bit worried about over usage... But you are right, I'll open it!
It should be working now with *

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test is still not ok ? 🧐

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you seeing any requests on your end? its weird because this only fails in the tests. if i try it in my browser it's fine. 🤔

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at "https://skyzoo.blue/stats/plc/did:plc:k6acu4chiwkixvdedcmdgmal".

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why is that in test env !
And don't manage to see "log" with "npm run test" I see the summary, but not live tests. It's a config issue ?

I'll look into it later 🤞

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may need to merge with the test skipped and revisit it. it works in the browser and thats what really matters.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure
I let you do ✌️

if (!response.ok) throw new Error('Failed to fetch SkyZoo stats');
return (await response.json()) as {
did: string;
pos_atproto: number;
pos_bsky: number;
createdAt: string;
};
},
});
}
Loading