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

Fix: broken Prettier configuration #850

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
20 changes: 10 additions & 10 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@

version: 2
updates:
- package-ecosystem: "pip"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This .github directory had been added to the .prettierignore file, so I removed it and formatted these files.

directory: "/"
- package-ecosystem: 'pip'
directory: '/'
schedule:
interval: "daily"
interval: 'daily'
# Raise pull requests for version updates
# to pip against the `develop` branch
target-branch: "fix/update-package-json-INT-122"
target-branch: 'fix/update-package-json-INT-122'
# Labels on pull requests for version updates only
labels:
- "pip dependencies"
- 'pip dependencies'

- package-ecosystem: "npm"
directory: "/"
- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: "weekly"
interval: 'weekly'
# Check for npm updates on Sundays
day: "sunday"
day: 'sunday'
# Labels on pull requests for security and version updates
labels:
- "npm dependencies"
- 'npm dependencies'
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ jobs:
- name: Install dependencies
run: pnpm install
- run: pnpm run lint
- run: pnpm run prettier . --check
- run: pnpm prettier . --check
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using pnpm run implies use of a package.json script - whereas in this context we want the binary (we don't want to run prettier . --write).


- run: pnpm run build
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dist
.nuxt
.github
pnpm-lock.yaml
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
],
"scripts": {
"lint": "eslint --max-warnings=0 './src/**/*.{ts,js}'",
"prettier": "prettier . --write",
"format": "prettier . --write",
"build": "node vite.build.mjs && tsc",
"demo": "vite serve playground",
"dev:umd": "npx serve ./",
Expand Down
174 changes: 89 additions & 85 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ describe('StoryblokClient', () => {
})

expect(client.client.baseURL).toBe('https://api-custom.storyblok.com/v2')

})
it('https: should set the http endpoint if option is set to false', () => {
client = new StoryblokClient({
Expand Down Expand Up @@ -153,85 +152,86 @@ describe('StoryblokClient', () => {
})

describe('cache', () => {

it('should return cacheVersions', async () => {
const mockThrottle = vi.fn().mockResolvedValue({
data: {
data: {
stories: [{ id: 1, title: 'Update' }],
cv: 1645521118
cv: 1645521118,
},
headers: {},
status: 200
});
client.throttle = mockThrottle;
await client.get('test', { version: 'draft', token: 'test-token' });
status: 200,
})
client.throttle = mockThrottle
await client.get('test', { version: 'draft', token: 'test-token' })

expect(client.cacheVersions()).toEqual({
'test-token': 1645521118
});
'test-token': 1645521118,
})
})

it('should return cacheVersion', async () => {
const mockThrottle = vi.fn().mockResolvedValue({
data: {
data: {
stories: [{ id: 1, title: 'Update' }],
cv: 1645521118
cv: 1645521118,
},
headers: {},
status: 200
});
client.throttle = mockThrottle;
await client.get('test', { version: 'draft', token: 'test-token' });
expect(client.cacheVersion('test-token')).toBe(1645521118);
status: 200,
})
client.throttle = mockThrottle
await client.get('test', { version: 'draft', token: 'test-token' })

expect(client.cacheVersion('test-token')).toBe(1645521118)
})

it('should set the cache version', async () => {
client.setCacheVersion(1645521118);
client.setCacheVersion(1645521118)
expect(client.cacheVersions()).toEqual({
'test-token': 1645521118
});
'test-token': 1645521118,
})
})

it('should clear the cache', async () => {
// Mock the cacheProvider and its flush method
// Mock the cacheProvider and its flush method
client.cacheProvider = vi.fn().mockReturnValue({
flush: vi.fn().mockResolvedValue(undefined),
});
})
// Mock the clearCacheVersion method
client.clearCacheVersion = vi.fn();
await client.flushCache();
client.clearCacheVersion = vi.fn()
await client.flushCache()

expect(client.cacheProvider().flush).toHaveBeenCalled();
expect(client.clearCacheVersion).toHaveBeenCalled();
expect(client.cacheProvider().flush).toHaveBeenCalled()
expect(client.clearCacheVersion).toHaveBeenCalled()
})

it('should clear the cache version', async () => {
client.clearCacheVersion('test-token');
expect(client.cacheVersion()).toEqual(0);
client.clearCacheVersion('test-token')
expect(client.cacheVersion()).toEqual(0)
})

it('should flush the cache when the draft version is requested and clear is auto', async () => {
client = new StoryblokClient({ cache: { clear: 'auto' } });
client = new StoryblokClient({ cache: { clear: 'auto' } })
client.cacheProvider = vi.fn().mockReturnValue({
flush: vi.fn().mockResolvedValue(undefined),
});
client.clearCacheVersion = vi.fn();
})
client.clearCacheVersion = vi.fn()
// Setup scenario where draft version triggers cache flush
await client.get('test-draft', { version: 'draft' });
await client.get('test-draft', { version: 'draft' })
// Ensure cache flush method was called
expect(client.cacheProvider().flush).toHaveBeenCalled();
expect(client.clearCacheVersion).toHaveBeenCalled();
});

expect(client.cacheProvider().flush).toHaveBeenCalled()
expect(client.clearCacheVersion).toHaveBeenCalled()
})
})

describe('get', () => {
it('should fetch data from the API', async () => {
const result = await client.get('test')
expect(result).toEqual({ data: {
links: 'Test data',
}, headers: {} })
expect(result).toEqual({
data: {
links: 'Test data',
},
headers: {},
})
})
})

Expand Down Expand Up @@ -267,7 +267,11 @@ describe('StoryblokClient', () => {
status: 200,
})
client.makeRequest = mockMakeRequest
const result = await client.getAll('cdn/links', { version: 'draft' }, 'custom')
const result = await client.getAll(
'cdn/links',
{ version: 'draft' },
'custom'
)
expect(result).toEqual([
{ id: 1, name: 'Test 1' },
{ id: 2, name: 'Test 2' },
Expand All @@ -294,62 +298,62 @@ describe('StoryblokClient', () => {
describe('post', () => {
it('should post data to the API', async () => {
const mockThrottle = vi.fn().mockResolvedValue({
data: {
stories: [{ id: 1, title: 'Keep me posted' }]
data: {
stories: [{ id: 1, title: 'Keep me posted' }],
},
headers: {},
status: 200
});
client.throttle = mockThrottle;
status: 200,
})
client.throttle = mockThrottle
const result = await client.post('test', { data: 'test' })
expect(result).toEqual({
expect(result).toEqual({
data: {
stories: [{ id: 1, title: 'Keep me posted' }]
},
stories: [{ id: 1, title: 'Keep me posted' }],
},
headers: {},
status: 200
status: 200,
})
})
})

describe('put', () => {
it('should put data to the API', async () => {
const mockThrottle = vi.fn().mockResolvedValue({
data: {
stories: [{ id: 1, title: 'Update' }]
data: {
stories: [{ id: 1, title: 'Update' }],
},
headers: {},
status: 200
});
client.throttle = mockThrottle;
status: 200,
})
client.throttle = mockThrottle
const result = await client.put('test', { data: 'test' })
expect(result).toEqual({
expect(result).toEqual({
data: {
stories: [{ id: 1, title: 'Update' }]
},
stories: [{ id: 1, title: 'Update' }],
},
headers: {},
status: 200
status: 200,
})
})
})

describe('delete', () => {
it('should delete data from the API', async () => {
const mockThrottle = vi.fn().mockResolvedValue({
data: {
stories: [{ id: 1, title: 'Delete' }]
data: {
stories: [{ id: 1, title: 'Delete' }],
},
headers: {},
status: 200
});
client.throttle = mockThrottle;
status: 200,
})
client.throttle = mockThrottle
const result = await client.delete('test')
expect(result).toEqual({
expect(result).toEqual({
data: {
stories: [{ id: 1, title: 'Delete' }]
},
stories: [{ id: 1, title: 'Delete' }],
},
headers: {},
status: 200
status: 200,
})
})
})
Expand All @@ -358,24 +362,24 @@ describe('StoryblokClient', () => {
const mockThrottle = vi.fn().mockResolvedValue({
data: { stories: [{ id: 1, title: 'Test Story' }] },
headers: {},
status: 200
});
client.throttle = mockThrottle;
status: 200,
})
client.throttle = mockThrottle
client.resolveStories = vi.fn().mockResolvedValue({
id: 1,
title: 'Test Story',
});

await client.cacheResponse('/test-url', { token: 'test-token', version: 'published' });

expect(client.resolveStories).toHaveBeenCalled();
expect(client.resolveCounter).toBe(1);
});

it('should return access token', () => {
expect(client.getToken()).toBe('test-token');
})
})


await client.cacheResponse('/test-url', {
token: 'test-token',
version: 'published',
})

expect(client.resolveStories).toHaveBeenCalled()
expect(client.resolveCounter).toBe(1)
})

it('should return access token', () => {
expect(client.getToken()).toBe('test-token')
})
})
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -733,4 +733,4 @@ class Storyblok {
}
}

export default Storyblok
export default Storyblok
2 changes: 1 addition & 1 deletion tests/api/index.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('StoryblokClient', () => {

it("get('cdn/stories/testcontent-draft', { version: 'draft' }) should return the specific story draft", async () => {
const { data } = await client.get('cdn/stories/testcontent-draft', {
version: 'draft'
version: 'draft',
})
expect(data.story.slug).toBe('testcontent-draft')
})
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineConfig({
coverage: {
include: ['src'],
reporter: ['text', 'json', 'html'],
reportsDirectory: './tests/unit/coverage'
reportsDirectory: './tests/unit/coverage',
},
},
})
Loading