Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/brave-swans-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@driimus/aws-event-factory": minor
---

refactor: replace deprecated faker methods
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

71 changes: 0 additions & 71 deletions .eslintrc.cjs

This file was deleted.

24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Logs
logs
*.log
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Dependencies
node_modules

Expand All @@ -7,3 +21,13 @@ dist

# Test coverage
coverage

# macOS files
.DS_Store

# editor files
.vscode
.idea

# Output of 'npm pack'
*.tgz
5 changes: 0 additions & 5 deletions .vscode/settings.json

This file was deleted.

94 changes: 94 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import eslint from '@eslint/js';
import prettier from 'eslint-plugin-prettier/recommended';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import turbo from 'eslint-plugin-turbo';
import unicorn from 'eslint-plugin-unicorn';
import vitest from 'eslint-plugin-vitest';
import tsEslint from 'typescript-eslint';

export default tsEslint.config(
{ ignores: ['packages/*/dist', 'packages/*/coverage', '**/*.d.ts', 'eslint.config.js'] },
eslint.configs.recommended,
...tsEslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
plugins: {
'simple-import-sort': simpleImportSort,
},
rules: {
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
// TODO: re-enable after flat config support
// 'import/first': 'error',
// 'import/newline-after-import': 'error',
// 'import/no-duplicates': 'error',
},
},
unicorn.configs['flat/recommended'],
{
files: ['**/*.ts'],
plugins: {
'@typescript-eslint': tsEslint.plugin,
},
rules: {
'prefer-const': ['error', { destructuring: 'all' }],
'unicorn/filename-case': ['warn', { case: 'camelCase' }],
'unicorn/prevent-abbreviations': 'warn',
'unicorn/no-null': 'off',
'unicorn/no-useless-switch-case': 'error',
'@typescript-eslint/member-ordering': 'warn',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'error',
'@typescript-eslint/no-non-null-assertion': 'warn',
'@typescript-eslint/no-unsafe-return': 'warn',
'@typescript-eslint/no-unsafe-call': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-misused-promises': [
'error',
{
checksConditionals: true,
},
],
'@typescript-eslint/no-unnecessary-type-assertion': 'warn',
'@typescript-eslint/require-await': 'warn',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/consistent-type-imports': 'error',
},
},
{
files: ['**/*.test.ts'],
plugins: {
vitest,
},
rules: {
...vitest.configs.recommended.rules,
'@typescript-eslint/no-unsafe-assignment': 'off',
},
languageOptions: {
globals: {
...vitest.environments.env.globals,
},
},
},
{
files: ['turbo.json'],
plugins: {
turbo,
},
rules: {
'turbo/no-undeclared-env-vars': 'error',
},
},
prettier,
);
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"private": true,
"description": "Utilities for processing batch records in AWS Lambda functions",
"license": "MIT",
"type": "module",
"author": {
"name": "Cristian Petre",
"email": "driimus@vivaldi.net"
Expand All @@ -27,14 +28,15 @@
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-turbo": "^1.11.3",
"eslint-plugin-unicorn": "^50.0.1",
"eslint-plugin-vitest": "^0.3.20",
"eslint-plugin-simple-import-sort": "^12.0.0",
"eslint-plugin-turbo": "^1.12.5",
"eslint-plugin-unicorn": "^51.0.1",
"eslint-plugin-vitest": "^0.3.22",
"fishery": "^2.2.2",
"prettier": "^3.2.4",
"turbo": "^1.10.2",
"typescript": "^5.3.3",
"typescript-eslint": "^7.1.1",
"vitest": "^1.2.1"
},
"packageManager": "pnpm@8.14.2+sha256.a2dd287205a53bb4322937530d4a17f86269f63fe00a62a03e9e458d3ad027ff",
Expand Down
10 changes: 8 additions & 2 deletions packages/aws-event-factory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ Test data factories for different AWS Lambda event sources. Built using [fishery
- [Amazon SQS](https://aws.amazon.com/sqs/)
- [Amazon SecretsManager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/rotating-secrets-lambda-function-overview.html)

## Goals

This package prioritizes structural integrity over veracity. While some of the generated data is truthful,
explicit inputs should always be provided for the parts of an event that you really care about.

## Installation

> **Warning**\
> [!WARNING]
> This is an ES only package. Before installing, make sure that your project's configuration supports ECMAScript modules.

```sh
Expand Down Expand Up @@ -55,6 +60,7 @@ More examples:
- [test SQS events](../sqs-permanent-failure-dlq/tests/index.test.ts)
- [test DynamoDB Streams events](../lambda-batch-processor/tests/dynamodb.test.ts)

## Similar projects
## Prior art

- [@serverless/event-mocks](https://github.com/serverless/event-mocks)
- [mock-aws-events](https://github.com/Metronome-Industries/node-mock-aws-events)
3 changes: 2 additions & 1 deletion packages/aws-event-factory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"exports": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc"
"build": "tsc",
"test": "vitest run"
},
"peerDependencies": {
"@faker-js/faker": "^8.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const userAttributeFactory = Factory.define<MockUserAttributes>(() => {
return {
sub: randomUUID(),
email_verified: 'true',
name: faker.name.fullName(),
name: faker.person.fullName(),
email: faker.internet.email(),
};
});
2 changes: 1 addition & 1 deletion packages/aws-event-factory/src/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const s3RecordFactory = Factory.define<S3EventRecord>(() => {
},
object: {
key: 'b21b84d653bb07b05b1e6b33684dc11b',
size: faker.datatype.number(),
size: faker.number.int(),
eTag: 'b21b84d653bb07b05b1e6b33684dc11b',
sequencer: '0C0F6F405D6ED209E1',
},
Expand Down
6 changes: 3 additions & 3 deletions packages/aws-event-factory/src/sns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { Factory } from 'fishery';

class SNSMessageAttributeFactory extends Factory<SNSMessageAttribute> {
string() {
return this.params({ Type: 'String', Value: faker.datatype.string() });
return this.params({ Type: 'String', Value: faker.string.sample() });
}

number() {
return this.params({ Type: 'Number', Value: faker.datatype.number().toString() });
return this.params({ Type: 'Number', Value: faker.number.int().toString() });
}

binary() {
Expand All @@ -19,7 +19,7 @@ class SNSMessageAttributeFactory extends Factory<SNSMessageAttribute> {
}

export const snsMessageAttributeFactory = SNSMessageAttributeFactory.define(() => {
return { Type: 'String', Value: faker.datatype.string() };
return { Type: 'String', Value: faker.string.sample() };
});

export const snsMessageFactory = Factory.define<SNSMessage>(() => {
Expand Down
6 changes: 3 additions & 3 deletions packages/aws-event-factory/src/sqs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export const sqsEventFactory = Factory.define<SQSEvent>(() => {

class SQSMessageAttributeFactory extends Factory<SQSMessageAttribute> {
string() {
return this.params({ dataType: 'String', stringValue: faker.datatype.string() });
return this.params({ dataType: 'String', stringValue: faker.string.sample() });
}

number() {
return this.params({ dataType: 'Number', stringValue: faker.datatype.number().toString() });
return this.params({ dataType: 'Number', stringValue: faker.number.int().toString() });
}

binary() {
Expand All @@ -42,5 +42,5 @@ class SQSMessageAttributeFactory extends Factory<SQSMessageAttribute> {
}

export const sqsMessageAttributeFactory = SQSMessageAttributeFactory.define(() => {
return { dataType: 'String', stringValue: faker.datatype.string() };
return { dataType: 'String', stringValue: faker.string.sample() };
});
11 changes: 11 additions & 0 deletions packages/aws-event-factory/tests/apiGateway.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { describe, expect, it } from 'vitest';

import { apiGatewayEventFactory } from '../src/index.js';

describe('apiGatewayEventFactory', () => {
it('should allow stringified bodies', () => {
const body = JSON.stringify({ foo: 'bar' });

expect(apiGatewayEventFactory.build({ body })).toMatchObject({ body });
});
});
13 changes: 13 additions & 0 deletions packages/aws-event-factory/tests/cloudWatchLogs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, expect, it } from 'vitest';

import { cloudWatchLogsEventFactory } from '../src/index.js';

describe('cloudWatchLogsEventFactory', () => {
it('should generate b64 encoded json data', () => {
const event = cloudWatchLogsEventFactory.build();

expect(() => {
JSON.parse(Buffer.from(event.awslogs.data, 'base64').toString());
}).not.toThrow();
});
});
14 changes: 14 additions & 0 deletions packages/aws-event-factory/tests/cognito.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expect, it } from 'vitest';

import * as cognitoHelpers from '../src/cognito/index.js';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { CustomEmailSenderEventFactory, ...factories } = cognitoHelpers;

it('cognito factories should work', () => {
for (const factory of Object.values(factories)) {
expect(factory.build()).toMatchObject({
triggerSource: expect.any(String),
});
}
});
11 changes: 11 additions & 0 deletions packages/aws-event-factory/tests/eventBridge.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { describe, expect, it } from 'vitest';

import { eventBridgeEventFactory } from '../src/index.js';

describe('eventBridgeEventFactory', () => {
it('should be buildable', () => {
expect(eventBridgeEventFactory.build()).toMatchObject({
id: expect.any(String),
});
});
});
Loading