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/copywith missing fields #103

Merged
merged 4 commits into from
Jan 12, 2022
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 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.0.0-beta.3

- 🐞  Fixed: `copyWith` was missing fields
- 🚦  Tests: Updated tests.

## 2.0.0-beta.1

- ❗️🛠  Changed: Renamed `Method` to use `HttpMethod` and refactored helper functions into extensions (`StringToMethod`, and `MethodToString`).
Expand Down
2 changes: 0 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import 'dart:developer';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:http/src/base_request.dart';
import 'package:http/src/base_response.dart';
import 'package:http_interceptor/http_interceptor.dart';
import 'package:shared_preferences/shared_preferences.dart';

Expand Down
6 changes: 3 additions & 3 deletions lib/extensions/multipart_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ extension MultipartRequestCopyWith on MultipartRequest {
method?.asString ?? this.method,
url ?? this.url,
)
..headers.addAll(headers ?? {})
..fields.addAll(fields ?? {})
..files.addAll(files ?? [])
..headers.addAll(headers ?? this.headers)
..fields.addAll(fields ?? this.fields)
..files.addAll(files ?? this.files)
..followRedirects = followRedirects ?? this.followRedirects
..maxRedirects = maxRedirects ?? this.maxRedirects
..persistentConnection =
Expand Down
2 changes: 1 addition & 1 deletion lib/extensions/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension RequestCopyWith on Request {
method?.asString ?? this.method,
url ?? this.url,
)
..headers.addAll(headers ?? {})
..headers.addAll(headers ?? this.headers)
..encoding = encoding ?? this.encoding
..body = body ?? this.body
..followRedirects = followRedirects ?? this.followRedirects
Expand Down
2 changes: 1 addition & 1 deletion lib/extensions/streamed_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extension StreamedRequestCopyWith on StreamedRequest {
method?.asString ?? this.method,
url ?? this.url,
)
..headers.addAll(headers ?? {})
..headers.addAll(headers ?? this.headers)
..followRedirects = followRedirects ?? this.followRedirects
..maxRedirects = maxRedirects ?? this.maxRedirects
..persistentConnection =
Expand Down
4 changes: 0 additions & 4 deletions lib/http/intercepted_http.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';

import 'package:http/http.dart';
import 'package:http_interceptor/http_interceptor.dart';

import 'intercepted_client.dart';
import 'interceptor_contract.dart';

/// Class to be used by the user as a replacement for 'http' with interceptor
/// support.
///
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: http_interceptor
description: A lightweight, simple plugin that allows you to intercept request and response objects and modify them if desired.
version: 2.0.0-beta.1
version: 2.0.0-beta.3
homepage: https://github.com/CodingAleCR/http_interceptor
issue_tracker: https://github.com/CodingAleCR/http_interceptor/issues
repository: https://github.com/CodingAleCR/http_interceptor
Expand Down
1 change: 0 additions & 1 deletion test/extensions/base_reponse_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:http/http.dart';
import 'package:http_interceptor/http_interceptor.dart';
import 'package:test/test.dart';

Expand Down
1 change: 0 additions & 1 deletion test/extensions/base_request_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:convert';

import 'package:http/http.dart';
import 'package:http_interceptor/http_interceptor.dart';
import 'package:test/test.dart';

Expand Down
15 changes: 10 additions & 5 deletions test/extensions/request_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:convert';

import 'package:http/http.dart';
import 'package:http_interceptor/http_interceptor.dart';
import 'package:test/test.dart';

Expand All @@ -10,7 +9,8 @@ main() {

setUpAll(() {
baseRequest = Request("GET", Uri.https("www.google.com", "/helloworld"))
..body = jsonEncode(<String, String>{'some_param': 'some value'});
..body = jsonEncode(<String, String>{'some_param': 'some value'})
..headers['some_header'] = 'header_value';
request = baseRequest as Request;
});

Expand Down Expand Up @@ -205,18 +205,23 @@ main() {
test('Request is copied with different encoding', () {
// Arrange
final newEncoding = Encoding.getByName('latin1');
final changedHeaders = {'content-type': 'text/plain; charset=iso-8859-1'};
final changedHeaders = {'content-type': 'text/plain; charset=iso-8859-1'}
..addAll(request.headers);

Request updatedHeadersRequest = request.copyWith(
headers: changedHeaders,
);

// Act
Request copied = request.copyWith(
Request copied = updatedHeadersRequest.copyWith(
encoding: newEncoding,
);

// Assert
expect(copied.url, equals(request.url));
expect(copied.method, equals(request.method));
expect(copied.headers.length, equals(request.headers.length));
expect(copied.headers, equals(changedHeaders));
expect(updatedHeadersRequest.headers, equals(request.headers));
expect(copied.body, equals(request.body));
expect(
copied.encoding,
Expand Down
9 changes: 7 additions & 2 deletions test/extensions/response_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:http/http.dart';
import 'package:http_interceptor/http_interceptor.dart';
import 'package:test/test.dart';

Expand All @@ -7,7 +6,13 @@ main() {
late Response response;

setUpAll(() {
baseResponse = Response("{'foo': 'bar'}", 200);
baseResponse = Response(
"{'foo': 'bar'}",
200,
headers: {
'some_header': 'header_value',
},
);
response = baseResponse as Response;
});

Expand Down
3 changes: 1 addition & 2 deletions test/models/retry_policy_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:http/http.dart';
import 'package:test/test.dart';
import 'package:http_interceptor/http_interceptor.dart';
import 'package:test/test.dart';

main() {
late RetryPolicy testObject;
Expand Down