Skip to content

Commit

Permalink
feat: Add createdAt key to json in registry (#532)
Browse files Browse the repository at this point in the history
* feat: Add `created` key to json in registry

* ref: createdAt

* ref: Add more type safety

* ref changelog

* reset changelog

* Add simple unit test

* Add mock
  • Loading branch information
HazAT authored Apr 11, 2024
1 parent 65a598e commit 69f6b14
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
48 changes: 48 additions & 0 deletions src/targets/__tests__/registry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
jest.mock('../../utils/githubApi.ts');
import { getGitHubClient } from '../../utils/githubApi';
import { RegistryConfig, RegistryTarget } from '../registry';
import { NoneArtifactProvider } from '../../artifact_providers/none';
import { RegistryPackageType } from '../../utils/registry';

describe('getUpdatedManifest', () => {
let mockClient: jest.Mock;

beforeEach(() => {
jest.resetAllMocks();
mockClient = jest.fn();
(getGitHubClient as jest.MockedFunction<
typeof getGitHubClient
// @ts-ignore we only need to mock a subset
>).mockReturnValue({ graphql: mockClient });
});

const target = new RegistryTarget(
{ name: 'pypi' },
new NoneArtifactProvider(),
{ owner: 'testSourceOwner', repo: 'testSourceRepo' }
);

it('check if createdAt exists', async () => {
const registryConfig: RegistryConfig = {
type: RegistryPackageType.SDK,
canonicalName: 'example-package',
};
const packageManifest = {
canonical: 'example-package',
};
const canonical = 'example-package';
const version = '1.2.3';
const revision = 'abc123';

const updatedManifest = await target.getUpdatedManifest(
registryConfig,
packageManifest,
canonical,
version,
revision
);

// check if property createdAt exists
expect(updatedManifest).toHaveProperty('createdAt');
});
});
10 changes: 9 additions & 1 deletion src/targets/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,15 @@ export class RegistryTarget extends BaseTarget {
);
}
// Update the manifest
const updatedManifest = { ...packageManifest, version };
const updatedManifest: {
version: string;
createdAt: string;
[key: string]: any;
} = {
...packageManifest,
version,
createdAt: new Date().toISOString(),
};

// Add file links if it's a generic app (legacy)
if (registryConfig.type === RegistryPackageType.APP) {
Expand Down

0 comments on commit 69f6b14

Please sign in to comment.